Problem with Select Script

Hi all,

I've got a problem with a SQL query.

I need to do the following:

Select * from Table where CarMake = 'Ford' BUT I what to Display All Ford Cars + the rest of the data too.

In other words..Display All Fords FIRST and then everything else and not just the Fords!

Hope there is a way to do this!

Thanks

ST3VO
ST3VOAsked:
Who is Participating?
 
Jai SConnect With a Mentor Tech ArchCommented:
insert into carss (carmake) values('dfd')
insert into carss (carmake) values('dfd')
insert into carss (carmake) values('dfd')
insert into carss (carmake) values('FORD')
insert into carss (carmake) values('FORD')
insert into carss (carmake) values('FORD')
insert into carss (carmake) values('FORD')
insert into carss (carmake) values('FORD')
insert into carss (carmake) values('ABC')
insert into carss (carmake) values('ABC')
insert into carss (carmake) values('dBC')

select case when carmake = 'FORD' then 1 else 2 end as orderseq,* from carss
order by 1
0
 
Jai STech ArchCommented:
select case when carmake = 'FORD' then 1 else 2 end as orderseq,* from [table]
order by 1
0
 
ST3VOAuthor Commented:
Could you post the actual script how it would go please?

0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
Jai STech ArchCommented:
i did not understand what you mean by THE ACTUAL SCRIPT
....
select case when carmake = 'FORD' then 1 else 2 end as orderseq,* from [table]
order by 1
...
i will explain my script...
the CASE WHEN will check whether the carmaek = 'FORD' then it will return 1 or else 2...
so when you ORDER BY the first column (which is either 1(for ford) or 2(for other) it will order the FORD first and the other carmakes next to it...

you dont need a WHERE condition here...
0
 
Jai STech ArchCommented:
my table
carss(carid int identity(1,1),carmake varchar(100))
0
 
ST3VOAuthor Commented:
Hmm...The reason I'm saying this is because I get an Unspecified Error.

I'm coding the SQL into my programming Envirnment.

The error come out whenever I use WHEN :o/

Any Ideas?

0
 
Jai STech ArchCommented:
are you not using MS SQL  ???
0
 
Jai STech ArchCommented:
--SELECT * from table where Carmake = 'FORD'
--UNION  ALL
--SELECT * from table where Carmake <> 'FORD'
0
 
ST3VOAuthor Commented:
No...I'm using Delphi's TQuery SQL :o/

0
 
ST3VOAuthor Commented:
Brilliant!!! Thanks :o)

I needed to modify it a little to:

SELECT * from Table where CarMake= 'FORD' UNION  ALL SELECT * from Table where CarMake <> 'FORD'

It's Perfect :o)

Cheers

ST3VO
0
 
Jai STech ArchCommented:
cheers... :-)
0
 
ST3VOAuthor Commented:
Opps Sorry I accepted the wrong one....

I should have accepted this post:

jaiganeshsrinivasan:
--SELECT * from table where Carmake = 'FORD'
--UNION  ALL
--SELECT * from table where Carmake <> 'FORD'

Still by jaiganeshsrinivasan thou!!!! :o)
0
 
Jai STech ArchCommented:
:-()
0
All Courses

From novice to tech pro — start learning today.