PDA

View Full Version : sql querying two tables and sorting by a date field..


romerom
01-25-2005, 04:40 AM
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?

raf
01-25-2005, 09:21 PM
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;