Select Queries

G

Guest

I need to write a query to get the record based on the condition. here i need
to fetch all records in the database but the records which match the
condition should be in the top position fallowed by the records which dosent
match the condition.

Ex.

Select * form CUSTDET Order BY CID
this will fetch all records in CUSTDET

Select * from CUSTDET Where CID=5
this will fetch all records of CID 5

i need to write a query which will fetch records containing CID as 5 then
fallowed by the records which contains CID other than 5

please help me
 
J

John Vinson

I need to write a query to get the record based on the condition. here i need
to fetch all records in the database but the records which match the
condition should be in the top position fallowed by the records which dosent
match the condition.

Ex.

Select * form CUSTDET Order BY CID
this will fetch all records in CUSTDET

Select * from CUSTDET Where CID=5
this will fetch all records of CID 5

i need to write a query which will fetch records containing CID as 5 then
fallowed by the records which contains CID other than 5

please help me

You need to separate the fetching from the sorting. Since the value
True is equal to -1 and False zero, True expressions sort before
False; try

SELECT * FROM CUSTDET
ORDER BY ([CID] = 5), <any other lower-level sort terms>


John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top