sql_language thread: SV: RE: Pick values out of more than 1 table..
Presumably the WHERE clause would be on each SELECT in the subquery. You
could do add the WHERE clause to the outer SELECT, but that may not be a
good idea, as you'd be UNIONing many irrelevant rows, and then excluding
them in the outer query.
"And actually I dunno if the user hasn't done 10 posts..?"
So do you want a maximum of 10 rows returned? The TOP clause simply
restricts the number of rows in the resultset to the number specified. If
there aren't that many, the TOP clause does nothing.
--
Jeff Mason Custom Apps, Inc.
Jeff@c...
-----Original Message-----
From: SD-Studios [mailto:info@s...]
Sent: Wednesday, July 17, 2002 6:20 PM
To: sql language
Subject: [sql_language] SV: RE: Pick values out of more than 1 table..
Thanks.. But I need to check a value too.. Like if the post is made by a
specific user. Where do I put the where-string? And actually I dunno if the
user hasn't done 10 posts..? Thanks a lot!
--
Cheers
Martin Johansson
CEO & Project Supervisor
SD-Studios, Squaremedia HB
+46 (0)70-3003320
http://www.sd-studios.com
http://www.swehost.com
-----Ursprungligt meddelande-----
Från: Jeff Mason [mailto:jeffm.ma.ultranet@r...]
Skickat: den 18 juli 2002 00:12
Till: sql language
Ämne: [sql_language] RE: Pick values out of more than 1 table..
Construct a union of all the tables as a subquery, then select the top 10
from that, as:
SELECT top 10 from
(select datecol from table1
union
select datecol from table2
union
select datecol from table3
...
order by datecol) as unionquery;
--
Jeff Mason Custom Apps, Inc.
Jeff@c...
-----Original Message-----
From: SD-Studios [mailto:info@s...]
Sent: Wednesday, July 17, 2002 5:54 PM
To: sql language
Subject: [sql_language] Pick values out of more than 1 table..
Hi!
I've got a no of tables, from which I'd like to select the 10 latest posts.
Not the 10 latest in each, but the 10 latest from all of them. Did you get
that? =) I've got date/time-fields in each table. Is this possible in some
way? Thanks!
--
MVH, Martin Johansson
CEO & Project Supervisor
SD-Studios, Squaremedia HB
+46 (0)70-3003320
http://www.sd-studios.com
http://www.swehost.com