PDA

View Full Version : JOIN 2 tables order by latest date...


jmansa
02-18-2010, 02:24 PM
I have a script which print out news form certain groups depending on which group the user is a member of and that works fine. Now I want to be able to ad news into the loop from another table depending on the users language and order them by date from both tables, I think join?!?!?

This is the working script:
$sql="SELECT u.fname, u.lname, u.new_userid, n.news, n.clubid, n.newsid, cl.clubname FROM ".$prefix."_club_users AS cu
INNER JOIN ".$prefix."_clubnews AS n ON cu.clubid = n.clubid
INNER JOIN ".$prefix."_users u ON u.new_userid = n.userid
INNER JOIN ".$prefix."_club cl ON cl.clubid = cu.clubid
WHERE cu.new_userid='$userid'
ORDER BY n.dbdate DESC
LIMIT 5";

And this is what I want added to the query:
$sql="SELECT lang, subject, content FROM ".$prefix."_news WHERE lang=$lang ORDER BY date DESC";

I guess I want to join the to date fields somehow (dbdate and date)...

Please help :-)

Fumigator
02-18-2010, 03:41 PM
Sounds more like a job for UNION.

http://en.wikipedia.org/wiki/Union_%28SQL%29