Select Queries

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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]
 
Back
Top