![]() |
|
|
|||||||
![]() |
|
|
Thread Tools | Rate Thread |
|
|
PM User | #1 |
|
New to the CF scene Join Date: Jan 2005
Location: Phoenix, AZ
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
sql querying two tables and sorting by a date field..
whats up everybody. I'm having an issue figuring out the correct sql query for some sorting logic for a website i just started helping out with.
i have two seperate mysql tables. each has a couple fields that are similar across the tables (for my intended purposes). I can't sort by uniqueID because they have different id's obviously being in different tables. We do however, have a date/time stamp column in both tables that I'd like to sort by. i came up with this.. but am not sure if the results i'm getting are accurate.. select artid,img,artist,date,info from cms_artists where info !='NULL' union select articleid,img,subject,date,text from cms_articles order by date desc limit 10; does that look right? |
|
|
|
|
|
PM User | #2 |
|
Master Coder ![]() ![]() Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
welcome here!
not sure what you are asking here. your query looks fine, but why don't you just run it and see if the results are as expected ? The !='NULL' looks a bit strange to. You probably mean IS NOT NULL it's also easier readable if you write it like this (select artid,img,artist,date,info from cms_artists where info !='NULL') union (select articleid,img,subject,date,text from cms_articles) order by date desc limit 10;
__________________
Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Rate This Thread | |
|
|