Bagisto Forum

    Bagisto

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Problem left join

    General Discussion
    2
    2
    192
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L
      LilD last edited by

      Hi, I have a problem when I want to give another left join in addresses, those data are apparently taken from me and I can't exclude them and conflicts arise.
      How could I just get what data I get from the address sheets and exclude the rest?

        $queryBuilder = DB::table('customers')
                  ->leftJoin('customer_groups', 'customers.customer_group_id', '=', 'customer_groups.id')
                  ->leftJoin('addresses', 'customers.id', '=', 'addresses.customer_id')
                  ->addSelect('customers.id as customer_id', 'customers.email', 'customer_groups.name', 'customers.phone', 'customers.gender', 'status')
                  ->addSelect('addresses.registration_number', 'addresses.vat_id')
                  ->addSelect(DB::raw('CONCAT(' . DB::getTablePrefix() . 'customers.first_name, " ", ' . DB::getTablePrefix() . 'customers.last_name) as full_name'));
      
      
      Integrity constraint violation: 1052 Column 'email' in where clause is ambiguous (SQL: select count(*) as aggregate from `customers` left join `customer_groups` on `customers`.`customer_group_id` = `customer_groups`.`id` left join `addresses` on `customers`.`id` = `addresses`.`customer_id` where (CONCAT(customers.first_name, " ", customers.last_name) like %
      
      1 Reply Last reply Reply Quote 0
      • devansh-webkul
        devansh-webkul last edited by

        Hi @LilD,

        Just append the alias to email, because emails are two so its not able to detect which one should he take,
        alias1.email, table_name.email

        1 Reply Last reply Reply Quote 0
        • First post
          Last post