Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Problem in SQL, need help
Tue, Jan 29 2008 10:49 AMPermanent Link

Eduardo Pereira
I need to UNION the results of three querys. Each query returns the top 50 records os each type.

SELECT ID, MODELO, VIN, DATAHORA FROM TBMEASUREMENTS
WHERE MODELO = 'Celta 3P'
TOP 50
UNION
SELECT ID, MODELO, VIN, DATAHORA FROM TBMEASUREMENTS
WHERE MODELO = 'Celta 5P'
TOP 50
UNION
SELECT ID, MODELO, VIN, DATAHORA FROM TBMEASUREMENTS
WHERE MODELO = 'Prisma'
TOP 50

The problem: The result is only 50 records of MODELO = 'Celta 3P'
Help!!!



Attachments: Database.rar
Tue, Jan 29 2008 11:17 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Eduardo


Try creating a script, squirting each of the individual queries into a memory table and then UNION those.

Remember to drop the memory tables when you've finished with them

Roy Lambert
Tue, Jan 29 2008 1:48 PMPermanent Link

"Malcolm"
Eduardo

Did you try increasing the TOP value for each union?

....
TOP 50
....
TOP 100
....
Top 150
Tue, Jan 29 2008 3:51 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Eduardo,

<< I need to UNION the results of three querys. Each query returns the top
50 records os each type. >>

You can only use TOP with the first query in a series of UNION, etc.
statements.  TOP is a "final" operation on the entire statement, so it is
only going to grab the first 50 rows of the final result set.

--
Tim Young
Elevate Software
www.elevatesoft.com

Image