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!

join query with or without cross table match

Status
Not open for further replies.

southbeach

Programmer
Jan 22, 2008
879
US
The subject line sounds too complicated for what follows:

PROBLEM:
I have two tables (articles and authors). I use the articles table for both articles and their respective responses. As of today, I have lived with the flaw that if a guest leaves a reply or submits an article, this will not appear since my query does not find an author to match the author in the articles table.

Here is the query I am using:
Code:
SELECT a.* , b.MemberFirstName , b.MemberLastName, c.Category from articles a , members b , categories c WHERE a.ParentID <= 0 AND a.AuthorID = b.MemberID AND a.CatID = c.CatID LIMIT ' . $start . ", " . $limit;

As you can see, the query will only return rows for those cases where the author is known. When adding a new article, I am defaulting the author ID to 0 if not logged in thus causing this problem.

WHAT I SEEK
I need a query I can use to select all as above and for those where no matching author is found, I would like to set a variable (something line author_name) to GUEST.


Thank you all in advance for your help!


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
SELECT a.* , b.MemberFirstName , b.MemberLastName, c.Category
from articles a
left outer join members b
on a.AuthorID = b.MemberID
left outer join categories c
on a.CatID = c.CatID LIMIT ' . $start . ", " . $limit
WHERE a.ParentID <= 0

Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top