Jump to content


Photo

Join and Order by Problem


  • Please log in to reply
2 replies to this topic

#1 kellerkind

kellerkind
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 27 September 2006 - 10:10 AM

Hi,
I'm new to join statements and it would be great if anyone could help me. I did some tutorials but I'm not sure if i can do what i want to do with join.

PROBLEM
I have a variable number of tables called "newsposts" (newsposts1, newsposts2, newsposts3...)
In each of these tables I have a column with "postdate".

I want to get the 10 latest entries from all "newsposts" tables.

SOLUTION?
So my idea was to first create an array with all names of "newsposts" tables and after that Join all these tables and use order by "postdate" with a limit of 10 to display the latest data from all "newsposts" tables.


QUESTION
Could it work like this and do you have an example of how such a join statement would look like?

Thanks a lot,
Jay

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 27 September 2006 - 06:41 PM

Best way is probably just to use a UNION, and the use an ORDER BY on the whole thing.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 kellerkind

kellerkind
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 27 September 2006 - 07:32 PM

Hey cool thanks a lot!

I did some weird stuff with 2dimensional arrays and have a couple of querries now but at least it works but I give union a try.
Muchas gracias!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users