Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 1 / February 2006

Tip: Looking for answers? Try searching our database.

Selecting Last 2

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mgreenway@gmail.com - 25 Feb 2006 23:30 GMT
aut_id    txt_head mem_body yon_approved
1                                               y
2                                               n
3                                               y
4                                               n
5                                               y
6                                               n

Trying to select  last two records added that are approved and the last
two that are not approved... what i want to return is
5
3
6
4

SELECT Top 2 * FROM tbl_page WHERE Yon_approved = True ORDER BY aut_id
DESC UNION ALL ELECT Top 2 * FROM tbl_page WHERE Yon_approved = False
ORDER BY aut_id DESC
Returns
5
4
3
2
Mark - 26 Feb 2006 00:14 GMT
I think you can do this with a _very_ ugly set of nested queries.

Try this:

SELECT [tbl_page].[aut_id]
FROM tbl_page
WHERE tbl_page.aut_id=(select max(aut_id) FROM tbl_page WHERE yon_approved =
"y") OR tbl_page.aut_id = (select max(aut_id) FROM tbl_page WHERE
yon_approved = "y" AND aut_id < (select max(aut_id) FROM tbl_page WHERE
tbl_page.yon_approved = "y"));

That should give you the "top two" approved entries.
If you get it working, try cloning it for the unapproved entries.
Your next challenge would be to splice both of them into a single query.

Good luck!
-Mark
mgreenway@gmail.com - 26 Feb 2006 00:53 GMT
(SELECT Top 2 * FROM tbl_page WHERE Yon_approved = True ORDER BY aut_id
DESC) UNION ALL (SELECT Top 2 * FROM tbl_page WHERE Yon_approved =
False
ORDER BY aut_id DESC)
Mark - 26 Feb 2006 03:47 GMT
> (SELECT Top 2 * FROM tbl_page WHERE Yon_approved = True ORDER BY aut_id
> DESC) UNION ALL (SELECT Top 2 * FROM tbl_page WHERE Yon_approved =
> False
> ORDER BY aut_id DESC)

Ok, the "top" keyword is a new one to me. Thanks.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.