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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Specific row on top of results 1

Status
Not open for further replies.

Sleidia

Technical User
May 4, 2001
1,284
FR
Hello everyone,

Someone knows how I could list all the records of a table with the very first result being of a specified value that exists in the table?

For example :

column 1
a
b
c
d

Query result with c needed on top :

c
a
b
d


Query result with b needed on top :

b
a
c
d


Thanks :)


 
Hi Sleidia, been a while :)

No help I'm afraid. brain dead. xmas. alcohol.

Have a good one.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Code:
order by (case when columnname='b' then 0 else 1 end)
 
How about:
[tt]
SELECT *
FROM tblname
ORDER BY colname='c' DESC
[/tt]
 

Hey ! ;)

Nice to see that you're still around !

I'm braindead too but it has nothing to do with Christmas ;)

Cheers
 

TonyGroves : I'm working on 2 tables on the same time and it doesn't seem to work.

guelphdad : I can't make your idea work either :(

Here is my query :

SELECT *
FROM cats AS cats_tab, prods AS prods_tab
WHERE prods_tab.prod_cat_ID = cats_tab.cat_ID
ORDER BY cats_tab.cat_ID

I want to make an arbitrary ordering on cat_ID

Thanks again guys
 
Either my or guelphdad's solution should work there as well. How do they not work?
 

Well, the problem is that the records order is totally weird.
 
works only in mysql --

ORDER BY
cats_tab.cat_ID='c' desc
, cats_tab.cat_ID

works in all databases --

ORDER BY
case when cats_tab.cat_ID='c' then 1 else 0 end desc
, cats_tab.cat_ID



r937.com | rudy.ca
 
Thanks r937 !!!

The last solution you provided worked for me.
I'd never been able to make it work without you.

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top