Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT a different value twice 1

Status
Not open for further replies.

LaundroMat

Programmer
Dec 2, 2003
67
BE
Hi,

Suppose I have these tables:
Code:
user: id, name
faq: id, question, answer, q_author, a_author
How can I do a SELECT on the faq table, and get the authors of the question and of the answer out of the user table?
This (naturally) doesn't work, but it gives an idea of what I'm trying to do:
Code:
SELECT question, answer, name as qname, name as aname 
FROM faq, user
WHERE user.id  = faq.q_author
AND user.id = faq.a_author

Thanks in advance.
 
You need to declare user twice in the FROM section. You then need to use an alias to differentiate the fields in the two joins that you will build. As it stands it is selecting of just one join and most likely no records will satisfy the WHERE criteria.

 
so
SELECT question, answer, q.name, a.name
FROM faq, user as q,user as a
WHERE q.id = faq.q_author
AND a.id = faq.a_author

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top