SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
Sep 6, 2001, 10:09 #1
- Join Date
- Jul 2001
- Location
- Poland/ Warsaw
- Posts
- 111
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
mysql - selecting from two tables in one query
One question: how can I make this:
SELECT * FROM catone order by id desc limit 5
SELECT * FROM cattwo order by id desc limit 5
in single query?
-
Sep 6, 2001, 12:26 #2
- Join Date
- Apr 2001
- Location
- My Computer
- Posts
- 2,808
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
SELECT * FROM catone,cattwo order by id desc limit 5
theres a small chance that's wrong, cause that's how it's done in sql, dunno bout MySQL.
but try it. probably'll work
-
Sep 6, 2001, 12:27 #3
- Join Date
- Jul 2000
- Location
- Perth Australia
- Posts
- 1,717
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
$yaks=mysql_query("SELECT * FROM catone,cattwo ORDER BY catone.id DESC");
while($row=mysql_fetch_assoc($yaks)){
while(list($key,$var)=each($row)){echo "$key , $var<br>";}}
should do the job.
DOH - Defender beat me to it !
-
Sep 6, 2001, 12:30 #4
- Join Date
- Apr 2001
- Location
- My Computer
- Posts
- 2,808
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Sep 6, 2001, 13:47 #5
- Join Date
- Jul 2001
- Location
- Poland/ Warsaw
- Posts
- 111
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hmmm, I was trying a query like this before (I use fetch_array), but this doesn't work - I get 10 (I added LIMIT 10) items but only from the first table.
One more time:
I have two tables. I want to get 5 newest items from each table in single mysql query. I know that is easy - I'm sure that I do query like this before, but... I don't remember how.
Bookmarks