If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Select Query in DB2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-22-11, 05:12
ashu000 ashu000 is offline
Registered User
 
Join Date: Apr 2011
Posts: 28
Select Query in DB2

Hi All,

I have to create a query which will return result from a table. I need to show all the records but top row will must show what user has searched in the table.

I tried a query but it is returning only 1 row that is the one user has searched and if I try to use this query with order by, it is not working.

Kindly suggest if someone is having any idea on this.


Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old 06-22-11, 05:28
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
If "what user has searched in the table" was same as the result of this query,
Code:
SELECT ...
 FROM  <the table>
 WHERE <some conditions>
your required query may look like...
Code:
SELECT ...
 FROM  <the table>
 ORDER BY
       CASE
       WHEN <some conditions> THEN
            0
       ELSE 1
       END
Reply With Quote
  #3 (permalink)  
Old 06-22-11, 06:07
ashu000 ashu000 is offline
Registered User
 
Join Date: Apr 2011
Posts: 28
Hi,


It is done using UNION keyword. Using UNION, I used two select queries to get required results.


Thanks.
Reply With Quote
Reply

Tags
order by, select

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On