Setting MySQL column names

Posted by Richard Mar. on Stack Overflow See other posts from Stack Overflow or by Richard Mar.
Published on 2010-06-05T14:48:53Z Indexed on 2010/06/05 14:52 UTC
Read the original article Hit count: 151

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql