mysql - One query join with multiple rows from one table -


ok, have 2 tables in mysql. 1 table holds customer information, other holds phone numbers. need join these tables in 1 query select 2 phone numbers phones table customer information. right query is:

select customers.name, phones.phone, phones2.phone  customers  left join phones on phones.customerid=customers.id  left join phones phones2 on phones2.customerid=customers.id  group customers.id; 

however, returns same phone number phone 1 , phone 2. need offset phones2 1, don't know how syntactically.

the phones in separate table because it's 1 many relationship.

i need in 1 query because i'm exporting directly csv.

help appreciated. in advance.

to avoid getting same phone number twice change this:

left join phones phones2 on phones2.customerid=customers.id  

to this:

left join phones phones2 on phones2.customerid=customers.id , phones2.phone <> phones.phone 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -