Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Order By

Status
Not open for further replies.

mickywall

Programmer
Sep 2, 2002
88
0
0
GB
Below is the field structure of my database table 'myTable'

ID (autonumber)
Title (text)
Featured (text)
DateandTime (date/time)

The field featured will either hold the value Y or N

I would like to execute an SQL statement which selects firstly all the records that have a Y in the Featured field - ordered by DateandTime DESC, and then go on and select all the rest of the records and ORDER by DateandTime DESC

SELECT ID, Title, Featured, DateandTime FROM myTable
ORDER BY Featured DESC, DateandTime DESC doesn't do what I want!

Is this possible based on the set up of the table.
Thanks.
 
That seems like it should work. Perhaps if you gave us an example of how it is sorting and how you want it to sort, we could see the problem.

Questions about posting. See faq183-874
Click here to learn Ways to help with Tsunami Relief
 
Code:
select ID, Title, Featured, DateandTime
From myTable
Order by
  case when Featured = 'Y' then 1 else 0 end desc, dateandtime desc

how about this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top