Ok, so I have two tables in MySQL. One table holds customer information, the other holds phone numbers. I need to join these tables in one query to select up to two phone numbers from the phones table as well as customer information. right now my query is:
SELECT customers.name, phones.phone, phones2.phone
FROM customers
LEFT JOIN phones ON phones.customerid=customers.id
LEFT JOIN phones AS phones2 ON phones2.customerid=customers.id
GROUP BY customers.id;
However, this returns the same phone number for phone 1 and phone 2. essentially what I need to do is offset phones2 by 1, but I don’t know how to do that syntactically.
The phones are in a separate table because it’s a one to many relationship.
I need this to be in one query because I’m exporting this directly to a csv.
Help is much appreciated. Thanks in advance.
To avoid getting the same phone number twice you could change this:
To this: