lys916 lys916 - 2 years ago 105
MySQL Question

mysql SELECT WHERE and SELECT again

I have two tables Customers and Customer_orders. I'm trying to SELECT customer's order by using Customer_ID from Customer table.

SELECT * FROM Customer_orders WHERE Customer_ID = SELECT ID FROM Customers WHERE Customer_name = 'John Doe'

This code does not work. How do I do this?

Answer Source

You need to JOIN those 2 tables and then query for what you need. Like this:

SELECT co.* 
FROM Customer_orders co 
INNER JOIN Customers c ON co.Customer_ID = c.ID 
WHERE c.Customer_name = 'John Doe';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download