|
|
| Author |
Message |
| t121anf |
This post is not being displayed .
|
 t121anf World Chat Champion

Joined: 23 Feb 2007 Karma :     
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| Kickstart |
This post is not being displayed .
|
 Kickstart The Oracle

Joined: 04 Feb 2002 Karma :     
|
 Posted: 14:01 - 20 Jul 2010 Post subject: |
 |
|
Hi
I will guess at MySQL (cos it makes it easy )
| Code: | SELECT SomeDate
FROM
(
SELECT aDate As SomeDate
FROM Table1
UNION
SELECT bDate As SomeDate
FROM Table2
UNION
SELECT cDate As SomeDate
FROM Table3
)
ORDER BY SomeDate LIMIT 1 |
Or
| Code: | SELECT MAX(SomeDate)
FROM
(
SELECT aDate As SomeDate
FROM Table1
UNION
SELECT bDate As SomeDate
FROM Table2
UNION
SELECT cDate As SomeDate
FROM Table3
)
|
All the best
Keith ____________________ Traxpics, track day and racing photographs - Bimota Forum - Bike performance / thrust graphs for choosing gearing |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| Wabby |
This post is not being displayed .
|
 Wabby Trackday Trickster
Joined: 25 Sep 2007 Karma :    
|
 Posted: 14:42 - 20 Jul 2010 Post subject: |
 |
|
| Code: | SELECT SomeDate
FROM
(
SELECT aDate As SomeDate
FROM Table1
UNION
SELECT bDate As SomeDate
FROM Table2
UNION
SELECT cDate As SomeDate
FROM Table3
)
ORDER BY SomeDate LIMIT 1 |
Will do it as KickStart has already said. ____________________ What restriction? |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| supZ |
This post is not being displayed .
|
 supZ World Chat Champion

Joined: 03 Feb 2009 Karma :   
|
 Posted: 16:01 - 20 Jul 2010 Post subject: |
 |
|
beaten to it  ____________________ CBR954RR - Daily toy
CBR600RR - Trackbike |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| t121anf |
This post is not being displayed .
|
 t121anf World Chat Champion

Joined: 23 Feb 2007 Karma :     
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| TQ |
This post is not being displayed .
|
 TQ Trackday Trickster
Joined: 17 Dec 2009 Karma :  
|
 Posted: 10:20 - 21 Jul 2010 Post subject: |
 |
|
| Code: | 1>SELECT TOP 1 RESERVATION.CREATE_DATE AS SOME_DATE FROM RESERVATION
2> WHERE RESERVATION.BORROWER_ID=17087
3> UNION
4> SELECT TOP 1 ILL_REQUEST.CREATE_DATE AS SOME_DATE FROM ILL_REQUEST
5> WHERE ILL_REQUEST.BORROWER_ID=17087
6> UNION
7> SELECT TOP 1 LOAN.CREATE_DATE AS SOME_DATE FROM LOAN
8> WHERE LOAN.BORROWER_ID=17087
9> ORDER BY SOME_DATE LIMIT 1
10> GO |
I'm not familiar with Sybase nor do I have a server to test on but try that. ____________________ First Bike :Gilera DNA 50 | Second: Imported 1989 NSR125
Third: 1998 Yamaha XJ600N | Currently: 1999 Yamaha FZS600 |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| supZ |
This post is not being displayed .
|
 supZ World Chat Champion

Joined: 03 Feb 2009 Karma :   
|
 Posted: 11:17 - 21 Jul 2010 Post subject: |
 |
|
not familar with sybase either myself but a 10 second google has told me that TOP doesnt work in sybase so you'll need to use ROWCOUNT instead.
as below..
| Code: |
SET ROWCOUNT 1
SELECT RESERVATION.CREATE_DATE AS SOME_DATE FROM RESERVATION
WHERE RESERVATION.BORROWER_ID=17087
UNION
ELECT ILL_REQUEST.CREATE_DATE AS SOME_DATE FROM ILL_REQUEST
WHERE ILL_REQUEST.BORROWER_ID=17087
UNION
SELECT LOAN.CREATE_DATE AS SOME_DATE FROM LOAN
WHERE LOAN.BORROWER_ID=17087
ORDER BY SOME_DATE DESC
SET ROWCOUNT 0
|
setting rowcount to 1 will only bring back 1 record
it should do this until rowcount is set back to 0 again
if it still doesnt work google the syntax for unions etc.. in sybase and make any changes you need to
i presume there is only one record per borrower_id? ____________________ CBR954RR - Daily toy
CBR600RR - Trackbike |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| t121anf |
This post is not being displayed .
|
 t121anf World Chat Champion

Joined: 23 Feb 2007 Karma :     
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| TQ |
This post is not being displayed .
|
 TQ Trackday Trickster
Joined: 17 Dec 2009 Karma :  
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| t121anf |
This post is not being displayed .
|
 t121anf World Chat Champion

Joined: 23 Feb 2007 Karma :     
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| t121anf |
This post is not being displayed .
|
 t121anf World Chat Champion

Joined: 23 Feb 2007 Karma :     
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| t121anf |
This post is not being displayed .
|
 t121anf World Chat Champion

Joined: 23 Feb 2007 Karma :     
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| TQ |
This post is not being displayed .
|
 TQ Trackday Trickster
Joined: 17 Dec 2009 Karma :  
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| t121anf |
This post is not being displayed .
|
 t121anf World Chat Champion

Joined: 23 Feb 2007 Karma :     
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| TQ |
This post is not being displayed .
|
 TQ Trackday Trickster
Joined: 17 Dec 2009 Karma :  
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| t121anf |
This post is not being displayed .
|
 t121anf World Chat Champion

Joined: 23 Feb 2007 Karma :     
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| TQ |
This post is not being displayed .
|
 TQ Trackday Trickster
Joined: 17 Dec 2009 Karma :  
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| t121anf |
This post is not being displayed .
|
 t121anf World Chat Champion

Joined: 23 Feb 2007 Karma :     
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| supZ |
This post is not being displayed .
|
 supZ World Chat Champion

Joined: 03 Feb 2009 Karma :   
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| Kickstart |
This post is not being displayed .
|
 Kickstart The Oracle

Joined: 04 Feb 2002 Karma :     
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| t121anf |
This post is not being displayed .
|
 t121anf World Chat Champion

Joined: 23 Feb 2007 Karma :     
|
 Posted: 15:56 - 22 Jul 2010 Post subject: |
 |
|
yeah for every borrower, its working now  |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| Kickstart |
This post is not being displayed .
|
 Kickstart The Oracle

Joined: 04 Feb 2002 Karma :     
|
 Posted: 16:09 - 22 Jul 2010 Post subject: |
 |
|
Hi
To save doing it separately for each borrower id then something like this might do it
| Code: |
SELECT SomeBorrowerId, MAX(SomeDate)
FROM
(
SELECT RESERVATION.BORROWER_ID AS SomeBorrowerId, MAX(RESERVATION.CREATE_DATE) AS SomeDate
FROM RESERVATION
GROUP BY RESERVATION.BORROWER_ID
UNION
SELECT ILL_REQUEST.BORROWER_ID AS SomeBorrowerId, MAX(ILL_REQUEST.CREATE_DATE) AS SomeDate
FROM ILL_REQUEST
GROUP BY ILL_REQUEST.BORROWER_ID
UNION
SELECT LOAN.BORROWER_ID AS SomeBorrowerId, MAX(LOAN.CREATE_DATE) AS SomeDate
FROM LOAN
GROUP BY LOAN.BORROWER_ID
) AS SubSelect1
GROUP BY SomeBorrowerId
|
You could probably lose the MAX and the GROUP BY from each of the unioned selects and just leave it round the outside. Might perform better or worse depending on your flavour of SQL.
All the best
Keith ____________________ Traxpics, track day and racing photographs - Bimota Forum - Bike performance / thrust graphs for choosing gearing |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
Old Thread Alert!
The last post was made 16 years, 45 days ago. Instead of replying here, would creating a new thread be more useful? |
 |
|
|