Apologies for my seriously rusty SQL... this should be easy.
I need to return values from two different rows of a left-joined table as two different columns in my SELECT query. Here's a simplified scheme of the two tables in question (I did NOT design this dbase!):
USERS table:
USER_ID | USER_NAME
PHONE_NUMBERS table:
USER_ID | PHONE_TYPE | PHONE_NUMBER
Any given user might have records in PHONE_NUMBERS where PHONE_TYPE = "Home", "Cell", or "Fax"
So I need to return a flattened list as follows:
USER_NAME | CELL_NUMBER | HOME_NUMBER
I tried:
SELECT USERS.USER_NAME, PHONE1.PHONE_NUMBER, PHONE2.PHONE_NUMBER
FROM USERS
LEFT JOIN PHONE_NUMBERS AS PHONE1
LEFT JOIN PHONE_NUMBERS AS PHONE2
WHERE PHONE1.PHONE_TYPE = "Home"
OR PHONE2.PHONE_TYPE = "Cell"
but it returns the same number in both phone columns. I feel like I'm so close...
VBAjedi
I need to return values from two different rows of a left-joined table as two different columns in my SELECT query. Here's a simplified scheme of the two tables in question (I did NOT design this dbase!):
USERS table:
USER_ID | USER_NAME
PHONE_NUMBERS table:
USER_ID | PHONE_TYPE | PHONE_NUMBER
Any given user might have records in PHONE_NUMBERS where PHONE_TYPE = "Home", "Cell", or "Fax"
So I need to return a flattened list as follows:
USER_NAME | CELL_NUMBER | HOME_NUMBER
I tried:
SELECT USERS.USER_NAME, PHONE1.PHONE_NUMBER, PHONE2.PHONE_NUMBER
FROM USERS
LEFT JOIN PHONE_NUMBERS AS PHONE1
LEFT JOIN PHONE_NUMBERS AS PHONE2
WHERE PHONE1.PHONE_TYPE = "Home"
OR PHONE2.PHONE_TYPE = "Cell"
but it returns the same number in both phone columns. I feel like I'm so close...
VBAjedi