| Author |
Topic  |
|
|
dcarroll
Starting Member
3 Posts |
Posted - 08/30/2011 : 09:39:10
|
I am new to SQL and programming in general, and I've found that it is easier to write large queries peicemeal and then combine the code by calling the queries in a main query as I need them. What I'm curious to know is, once I've written my the code this way is there any easy way to combine the smaller queries into one large query? |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47023 Posts |
Posted - 08/30/2011 : 09:43:03
|
depending on your scenario you can use both UNION or JOIN operators for merging your small queries
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
gwilson67
Starting Member
USA
42 Posts |
Posted - 08/30/2011 : 09:46:58
|
Union or Union All
Difference is that Union will remove the duplicates and Union All includes all records including duplicates.
Greg http://www.freewebstore.org/tsqlcoderepository Powerful tool for SQL Server development |
 |
|
|
dcarroll
Starting Member
3 Posts |
Posted - 08/30/2011 : 14:22:21
|
the " Main Query"
SELECT First(qryTom3.CruiseID) AS FirstOfCruiseID, First(qryTom3.SpeciesID) AS FirstOfSpeciesID, qryTom3.CommonName, First(qryTom3.EventNum) AS FirstOfEventNum1, Avg(IIf(IsNull([TotCt]),0,[TotCt])) AS Mean, StDev(IIf(IsNull([TotCt]),0,[TotCt])) AS StDev FROM qryTom3 LEFT JOIN qryTom1 ON (qryTom3.SpeciesID = qryTom1.SpeciesID) AND (qryTom3.EventNum = qryTom1.EventNum) GROUP BY qryTom3.CommonName; qryTom3 SELECT Station.CruiseID, Station.EventNum, Species.SpeciesID, Species.CommonName, Species.SurveySpecies FROM Species, Station WHERE (((Species.SurveySpecies)="TRUE"));
qryTom1
SELECT Station.CruiseID, Station.EventNum, CatchSummary.SpeciesID, CatchSummary.TotCt FROM Station INNER JOIN CatchSummary ON Station.EventNum=CatchSummary.EventNum;
My problem is that I can't figure out how to compile these queries into a single query |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47023 Posts |
Posted - 08/31/2011 : 00:20:48
|
are you using sql server? First is not a function in sql server
also can you show sample data from queries and then how you want to get merged output
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
| |
Topic  |
|