sql - MySQL - Limit the amount of rows in a join? -


Not sure here for some guidance ...

I have the following applause:

  site_text id site_id text date_added 1 1 ... 2010-02-02 10:01:00 2 1 ... 2010-02-02 10:01:20 3 2 ... 2010- 02 -02 10:01:00 4 1 ... 2010-02-02 10:01:40 5 2 ... 2010-02-02 10:02:00 Sites ID Site 1 Name 1 www.a.com 2 Www.b.com ....  

I am trying to select the last 2 rows in site_text for each site (ordered based on date). Can you do it with a question? Something like that, but does it only get 2 rows of each site?

  Select from sites_text include sites at st.site_id = s.id WHERE st.date_added & gt; '2010-02-01 23:32:04' by command s.id, st.date_added DESC  

Edit: Finally, I'm searching for lines 4,2, 5, 3.

There is a clever solution with CTE, and rank () PG 8.4 in DATE_ADDED but because you are using mysql, the only thing I can think of is that it contains a very computationally complex query:

  - Select the top date for each site_id, site_ect by site_id, site_id by date_ added ORDER, date_added union - select the top date for each site Site_id select site_id by site_text group site_id, date_added - excluding top date, where not (site id by site_text group location select id, date_added ORDER site_id, date_added) by ORDER site_id, date_added;  

The moral of the story, use the page to do so may be a more mysql-specific way to produce more acceptable display profiles.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -