Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

two selects in one query

Status
Not open for further replies.

almoes

Programmer
Jan 8, 2003
291
US
Hi all!

Is there any way of executing to non dependant select statements in one query, so like the result query contains the fields of two select statements. Something like select...AND select...

thanxs!
alej
 
If you're trying to select the same type of data from two distinct tables, then a basic Union query would work.

Select Field1, Field2, Field 3 from TableA where Field1 = "parameter"
UNION
Select Field1, Field2, Field 3 from TableB where Field1 = "parameter"

Is that what you're after?
 
thanxs but nop...i think what youo suggest will give a result of 3 fields, I need a result of 6 fields :-S
 
So your results will be six columns. Are the first columns from one table, and the last columns from another table? Or are all six columns found in both tables? Give me an example of the tables you are querying and the results you are hoping for.
 
ok, they are a bit complex but basically its this.

SELECT City, Sum(CountOf)
FROM [Select City1 as City, count(*) as CountOf from testTable group by City1 UNION ALL Select City2, count(*) from testTable group by City2)
GROUP BY City

and

SELECT Country, Sum(CountOf)
FROM [Select Country1 as Country, count(*) as CountOf from testTable group by Country1 UNION ALL Select Country2, count(*) from testTable group by Country2)
GROUP BY Country

So all fields are in the same table and the result woould be four fields: City, Expr1, Country, Expr2

 
Sorry. I don't know how to do that in one query. I would end up joining the two queries shown in a third one to get the results.
 
I dont know if its possible at all..what would you do? I dont get it...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top