|
JOIN, JOIN LEFT
Date: 10/18/05
(MySQL Communtiy) Keywords: mysql, sql
Hello, I've never used JOIN before and I am having some problems.
I have two tables invoice_main, clients
Invoice Main does not have the client's name in it, only their ID number. My project manager is asking to sort the names alphabetically. I thought I could grab the last name out of clients and append it on to invoice_main .
This is my query:
SELECT invoice_number, invoice_date, due_date, clientid, subtotal, paid_amounts, payment_status, ClientLast FROM invoice_main LEFT JOIN clients ON invoice_main.clientid=clients.ClientID WHERE office_id='1' ORDER BY ClientLast
This is the MySQL error
Column: 'clientid' in field list is ambiguous
SOLVED
Corrected query:
SELECT invoice_number, invoice_date, due_date, invoice_main.clientid, subtotal, paid_amounts, payment_status, ClientLast FROM invoice_main LEFT JOIN clients ON invoice_main.clientid=clients.ClientID WHERE invoice_main.office_id='1' ORDER BY ClientLast
By the way, yes its clientid in one table and ClientID in the other. I didn't create the tables and we are way too far into the project, near the end, to fix it.
Source: http://www.livejournal.com/community/mysql/70503.html
|