Setting MySQL column names
- by Richard Mar.
Say I have these tables:
people(id, name),
cars(person_id, car)
and this query:
SELECT c.car
FROM people as p, cars as c
WHERE c.person_id = p.id
AND p.id = 3
I want the c.car column to take its name from the name field in the people table, like this (invalid SQL, just to illustrate):
SELECT c.car AS(SELECT name FROM people WHERE id = 3)
How do I do that?