Hi,
Imagine the following case:
We have 2 tables:
cars: Contains a list of cars
car_owners: Contains a list of car owners
Every car owner is capable of owning one car and in the 'car_owners' table we have foreign key (fk_car_id) to the owners car in the 'cars' table.
I hope you're able to keep up so far!
Now, I can simply fetch a list of car owners ordered by their priority with this SQL:
SELECT * FROM car_owners ORDER BY priority
Easy! But what I really, really want, is to fetch a list of cars ordered by the priority of their owners!
The following doesn't work:
SELECT * FROM cars WHERE id IN ( SELECT fk_car_id FROM car_owners ORDER BY priority )
Because the IN-clause doesn't guarantee this! The cars are just returned in any order if their id is part of the subquery!
What am I missing here???
I Hope somebody can help me out of my confusion about this!
