In MySQL I have two tables, say Customers and Orders, looking like this:
[Customers]
'ID' 'Name' 'Phone_nr'
1 Ted 12345
2 Anna 54321
3 Anna 98765
[Orders]
'ID' 'Customer_ID' 'Price'
1 2 100
2 2 50
3 1 70
4 2 120
5 3 80
Now i want to search for orders ID where ‘Customers.Name = Anna’ and Price > 60… I was hoping i do something like:
SELECT 'ID' FROM 'Orders' WHERE 'Customer_ID' = (SELECT 'ID' FROM 'Customers' WHERE 'Name' = 'Anna') AND 'Price' > 60
I want this to return Order IDs 1, 4 and 5.
So basically, make a search based on ID numbers found by a search in an other table…
This will likely be done on large tables with maybe 1k results for “Anna”, i would also be open to other ways of structuring the tables, especially if it requires less of the server, but i still have items in one table that are linked to items in an other table, and i need to filter both.
Hope i’m being clear about this, and thanks for your time.
1 Answer