Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Old 01-25-2005, 04:40 AM   PM User | #1
romerom
New to the CF scene

 
Join Date: Jan 2005
Location: Phoenix, AZ
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
romerom is an unknown quantity at this point
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?
romerom is offline   Reply With Quote
Old 01-25-2005, 09:21 PM   PM User | #2
raf
Master Coder


 
Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
raf is on a distinguished road
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
raf is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:48 PM.

Home - Contact Us - Archives - Link to CF - Resources - Top 

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.