473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

order by where....

Pleas ehelp me with this.

I am performing a basic sql query.

select * from tablename order by featured asc, id asc

BUT...I want all those listings with FEATURED as a Y to show up first.
All other listings should show up afterwards.

How do I do this? I may be thinking too hard about it.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #1
6 1441
What's special about the "Y" ones, I mean you might be able to use a third
criteria in the order by clause if there is...
Otherwise you'll have to do it manually I think.

Curt

"Joey Martin" <jo**@infosmiths.net> wrote in message
news:OC***************@TK2MSFTNGP09.phx.gbl...
Pleas ehelp me with this.

I am performing a basic sql query.

select * from tablename order by featured asc, id asc

BUT...I want all those listings with FEATURED as a Y to show up first.
All other listings should show up afterwards.

How do I do this? I may be thinking too hard about it.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #2
Joey Martin wrote:

select * from tablename order by featured asc, id asc

BUT...I want all those listings with FEATURED as a Y to show up first.
All other listings should show up afterwards.


This will work if [Featured] is CHAR(1):

ORDER BY CHARINDEX(Featured,'Y') DESC
In general, you can use this technique on any CHAR/VARCHAR type if you
muliply the crossed CHARINDEX values:

SELECT * FROM States
ORDER BY
CHARINDEX(Name,"Virginia") * CHARINDEX("Virginia",Name) DESC,
Name ASC
The multiplication prevents false positives such as "West Virginia".

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Jul 19 '05 #3
Joey Martin wrote:
Pleas ehelp me with this.

I am performing a basic sql query.

select * from tablename order by featured asc, id asc

BUT...I want all those listings with FEATURED as a Y to show up first.
All other listings should show up afterwards.

How do I do this? I may be thinking too hard about it.

What database? Type and version please.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 19 '05 #4
Dave Anderson wrote:
Joey Martin wrote:

select * from tablename order by featured asc, id asc

BUT...I want all those listings with FEATURED as a Y to show up
first. All other listings should show up afterwards.


This will work if [Featured] is CHAR(1):

ORDER BY CHARINDEX(Featured,'Y') DESC

Only if he is using SQL Server ...

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 19 '05 #5
Bob Barrows [MVP] wrote:
Dave Anderson wrote:
Joey Martin wrote:

select * from tablename order by featured asc, id asc

BUT...I want all those listings with FEATURED as a Y to show up
first. All other listings should show up afterwards.


This will work if [Featured] is CHAR(1):

ORDER BY CHARINDEX(Featured,'Y') DESC

Only if he is using SQL Server ...


Or Sybase.

But I should think instr() would do the job in Oracle or MySQL...


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Jul 19 '05 #6
Dave Anderson wrote:
Bob Barrows [MVP] wrote:
Dave Anderson wrote:
Joey Martin wrote:

select * from tablename order by featured asc, id asc

BUT...I want all those listings with FEATURED as a Y to show up
first. All other listings should show up afterwards.

This will work if [Featured] is CHAR(1):

ORDER BY CHARINDEX(Featured,'Y') DESC

Only if he is using SQL Server ...


Or Sybase.

But I should think instr() would do the job in Oracle or MySQL...


Maybe. But my point is that the answer depends on the database being used,
which information was not provided by the OP.

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Xenophobe | last post by:
I have successfully converted the ASP code included in the following article to PHP: http://www.4guysfromrolla.com/webtech/040100-1.shtml As described the high and low latitudes and longitudes...
4
by: Bryan Harrington | last post by:
Can you use Select top 40 * from ... and ORDER BY... in the same query? I have the following 4 quearies that are.. for the most part, the same except the order by clause, all return a differnt...
0
by: Ed | last post by:
------=_NextPart_000_001D_01C34FCC.1D2B5E50 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable There seems to be a significant penalty imposed by the...
13
by: Dark Rayden | last post by:
Hi! I recently got a strange problem and I have no idea on the solution. I try to do a ORDER BY statement with a fixed order of values, because my client want's it this way. My approach is...
1
by: Tom Schindl | last post by:
Hi, the following Statement worked on MySQL 4.0 but after upgrading to 4.1.12 on win32 the order is not working any more. Is this a known problem or is our SQL simply not useable on 4.1 or is...
9
by: Frederik | last post by:
Hi all, I'm building a C# application that uses a M$ Acces database. In one of the queries I use something like the following: SELECT id FROM mytable WHERE id IN (20, 12, 21, 14) The result...
5
by: chadsmith76 | last post by:
hello, I have listings with coordinates, i would like to do ORDER BY and display listings with coords first. If they don't have coords the value is blank and the coords go both positive and...
3
by: Hartmut Dippon | last post by:
Hi all, I hope somebody can help me with following problem: I have an application where I can drag&drop files/dirs from within explorer onto my form. If multiple files/dirs are selected I...
54
by: Rasjid | last post by:
Hello, I have just joined and this is my first post. I have never been able to resolve the issue of order of evaluation in C/C++ and the related issue of precedence of operators, use of...
4
by: fluff | last post by:
Hello. I want to display some data from a database in a certain order. I have a table with columns A, B, Date. I want to display the records that have data in column A first and I want those...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.