Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JDBC and the fly likes Is it possible to connect 2 select statements into one Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Is it possible to connect 2 select statements into one" Watch "Is it possible to connect 2 select statements into one" New topic
Author

Is it possible to connect 2 select statements into one

john mattucci
Ranch Hand

Joined: Nov 03, 2000
Posts: 331
ELSE IF(@number = 2)
BEGIN
SELECT COUNT([outlet #])
FROM OM
WHERE [address] LIKE '%' + @address + '%';
SELECT [outlet #], [name], address, [city/town], [postal code], telephone
FROM OM
WHERE address LIKE '%' + @address + '%'
END
Would it be possible to obtain the # of records and records in one shot
Thank u for your time
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

You would want to use a sub query. I am not sure if what I am showing you will work, but it will be something similar to:
SELECT [outlet #], [name], address, [city/town], [postal code], telephone, (SELECT COUNT([outlet #]))
FROM OM
WHERE address LIKE '%' + @address + '%'
Hope that helps.
BTW - The query will be analized starting with the sub query, so it will do the COUNT first and then work it's way out.
[ September 02, 2002: Message edited by: Gregg Bolinger ]

GenRocket - A Test Data Generation Platform
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is it possible to connect 2 select statements into one
 
Similar Threads
Pagination
What am I doing wrong in this Stored Procedure
Table Relationship
What is Om?
how can i get column name of a table