How do I access column data in a previous select statement from a sub-query? [closed]
- by payling
PROBLEM
How do I access column data in a previous select statement from a sub-query?
Below is a simple mock up of what I'm attempting to do.
Tables used: Quotes, Users
QUOTES TABLE
qid, (quote id)
owner_uid,
creator_uid
SQL SYNTAX:
SELECT q.qid, q.owner_uid, q.creator_uid, owner.fname, owner.lname FROM quotes q, (SELECT u.fname, u.lname FROM users u WHERE u.uid = q.owner_uid) AS owner WHERE q.qid = '#'
SUMMARY
I want to be able to use the quote table's owner_uid and specify it for the owner table so I can return all the owner info for that particular quote.
The problem is, q.owner_uid is not recognized in the owner sub-query. What am I doing wrong?