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 > Sybase > New help filtering to one record per ID

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Dec 2012
Posts: 1
New help filtering to one record per ID

Hi,

Forgive my terminology if I get it wrong as I'm just teaching myself SQL. I have the following query:
Code:
SELECT ROOMS.ROOMNUMBER AS 'Room Number',
       ROOMS.ROOMSTATUS AS 'Status of Room',
       FOLIOHD.CHECKIN AS 'Current C/In Date',
       FOLIOHD.CHECKOUT AS 'Current C/Out Date',
       ROOMS.LASTOCCDATE AS 'Last C/Out Date',
       FOLIOHD.HOUSENOTE AS 'Housekeeping Note',
       ROOMBOOK.FROMDATE AS 'Next C/In Date',
       ROOMBOOK.TODATE AS 'Next C/Out Date'
 
FROM ROOMS
LEFT OUTER JOIN FOLIOHD ON ROOMS.ROOMNUMBER = FOLIOHD.ROOMNUMBER
LEFT OUTER JOIN HISTHD ON ROOMS.LASTFOLIO = HISTHD.NUMBER
JOIN ROOMBOOK ON ROOMS.ROOMNUMBER = ROOMBOOK.ROOMNUMBER
 
WHERE ROOMS.ROOMNUMBER <> '103' AND  ROOMS.ROOMNUMBER <> '110' AND  ROOMS.ROOMNUMBER <> '210' AND  ROOMS.ROOMNUMBER <> '227' AND  ROOMS.ROOMNUMBER <> '228'
which is working except it returns a separate row for each value in ROOMBOOK.FROMDATE, so I get something like this:
Code:
Room Number	Status of Room	Current C/In Date	Current C/Out Date	Last C/Out Date	Housekeeping Note	Next C/In Date	Next C/Out Date
104	O	26/12/12	27/12/12	26/12/12		27/12/12	01/01/13
104	O	26/12/12	27/12/12	26/12/12		02/01/13	04/01/13
104	O	26/12/12	27/12/12	26/12/12		04/01/13	05/01/13
104	O	26/12/12	27/12/12	26/12/12		05/01/13	19/01/13
104	O	26/12/12	27/12/12	26/12/12		19/01/13	06/04/13
104	O	26/12/12	27/12/12	26/12/12		06/04/13	13/04/13
104	O	26/12/12	27/12/12	26/12/12		26/04/13	28/04/13
104	O	26/12/12	27/12/12	26/12/12		19/07/13	20/07/13
104	O	26/12/12	27/12/12	26/12/12		11/08/13	12/08/13
105	V			24/12/12		26/12/12	28/12/12
105	V			24/12/12		28/12/12	29/12/12
105	V			24/12/12		29/12/12	30/12/12
105	V			24/12/12		30/12/12	01/01/13
105	V			24/12/12		02/01/13	04/01/13
105	V			24/12/12		05/01/13	19/01/13
105	V			24/12/12		19/01/13	06/04/13
105	V			24/12/12		06/04/13	13/04/13
105	V			24/12/12		26/04/13	28/04/13
105	V			24/12/12		19/07/13	20/07/13
105	V			24/12/12		11/08/13	12/08/13
106	V			26/12/12		26/12/12	27/12/12
106	V			26/12/12		27/12/12	01/01/13
106	V			26/12/12		02/01/13	04/01/13
106	V			26/12/12		11/01/13	19/01/13
106	V			26/12/12		19/01/13	06/04/13
106	V			26/12/12		06/04/13	13/04/13
I only want it to return the earliest value for ROOMBOOK.FROMDATE (ie: the next check/in, not all future checkins). How do I filter for this?

Thanks,
Reply With Quote
Reply

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