Reputation: 2236
I'm trying to select data from three different tables. How would I go about joining these tables to make the proper query?
****customers****
--------------------------
id full_name
54 Matt Damon
53 Jimmy Kimmel
****samples****
--------------------------
id rma_id
57 USARP011315-25
56 USARP011315-24
****early_ships****
--------------------------
customer_id sample_id shipping_carrier
54 57 UPS
53 56 FedEx
This is the query I've been running but I've yielded 0 results. This is the tutorial I've been following: http://javarevisited.blogspot.com/2012/11/how-to-join-three-tables-in-sql-query-mysql-sqlserver.html
SELECT samples.rma_id, customers.full_name, early_ships.shipping_carrier,
FROM customers c JOIN early_ships e ON c.id = e.customer_id
JOIN samples s ON e.sample_id = s.id
Upvotes: 0
Views: 88
Reputation: 1713
You have to use the table aliases in the SELECT
clause. Please check this fiddle I created for you. It's working perfectly. http://sqlfiddle.com/#!2/49462/8
Upvotes: 2
Reputation: 419
Two issues:
Try this:
SELECT s.rma_id, c.full_name, e.shipping_carrier
FROM customers c
JOIN early_ships e
ON c.id = e.customer_id
JOIN samples s
ON e.sample_id = s.id
(whitespace added for readability)
Upvotes: 1