php - SQL join left and right -


this query:

select distinct *  purchase_records  inner join purchase_items b on a.id = b.purchase_id  left join transactions c on a.id= c.purchase_id 

it fetches records 2 tables. left gets 1 record, , right gets number of records more one.

the issue when table returns record, matches exact record repeat right side of row according left side of row.

how can 1 record in left , many records in right? want left join show 1 record, , right show many records there in database.

the join table in database

you can try as....

    select a.*,b.add1,c.add2 from(     select 1 id,'a' name union     select 2 ,'b'  union     select 3 ,'c' union     select 4 ,'d')     left join      (select 1 id,'a' name,'z' add1 union     select 5 ,'b' ,'zz'  union     select 6 ,'c' ,'zzz' union     select 4 ,'d' ,'zzzz')b on a.id=b.id     right join     (select 1 id,'a' name,'1z' add2 union     select 5 ,'b' ,'1zz'  union     select 6 ,'c' ,'1zzz' union     select 4 ,'d' ,'1zzzz')c on c.id=a.id 

or like..

select a.columns,b.columns,c.columns your_table1 left join your_table2 b on a.id=b.id right join your_table3 c on c.id=a.id 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -