Dear All,
We are looking for your help. We are creating a query that extract the data from several tables (as usual), but we would like to do a Union between two primary tables. An example of how our SQL query looks like is below. How can we achieve this using the Query Builder? So far, we can query the db using only the first part of the query before the UNION statement. We have read the JSL books, but we could not find what we are looking for. Your help is highly appreciated!
So the original SQL query looks something like this:
USE BLAH -- this is the name of the DB
(SELECT
GENO.NAME AS [GENOTYPE],
GENO.PEDIGREE AS [PEDIGREE],
EXPMT.NAME AS [EXPERIMENT],
LOC.NAME AS [LOCATION],
TRAITS.NAME AS [TRAIT],
MEANS.YEAR AS [YEAR],
MEANS.AVG AS [DATA]
FROM BLAH.dbo.MEANS
INNER JOIN BLAH.dbo.GENO ON GENO.ID=MEANS.ENT1
INNER JOIN BLAH.dbo.EXPMT ON EXPMT.ID=MEANS.EXPT
INNER JOIN BLAH.dbo.LOC ON LOC.ID=EXPMT.LOC
INNER JOIN BLAH.dbo.TRAITS ON TRAITS.ID=MEANS.TRAIT
WHERE GENO.NAME IN ('a', 'b', 'c')
AND TRAITS.NAME = 'YIELD'
AND LOC.NAME = 'FARGO'
AND MEANS.YEAR IN ('2015','2016','2017'))
UNION(
SELECT
GENO.NAME AS [GENOTYPE],
GENO.PEDIGREE AS [PEDIGREE],
EXPMT.NAME AS [EXPERIMENT],
LOC.NAME AS [LOCATION],
TRAITS.NAME AS [TRAIT],
MEANS2.YEAR AS [YEAR],
MEANS2.AVG AS [DATA]
FROM BLAH.dbo.MEANS2
INNER JOIN BLAH.dbo.GENO ON GENO.ID=MEANS2.ENT1
INNER JOIN BLAH.dbo.EXPMT ON EXPMT.ID=MEANS2.EXPT
INNER JOIN BLAH.dbo.LOC ON LOC.ID=EXPMT.LOC
INNER JOIN BLAH.dbo.TRAITS ON TRAITS.ID=MEANS2.TRAIT
WHERE GENO.NAME IN ('a', 'b', 'c')
AND TRAITS.NAME = 'ALPHA_AMYLASE'
AND LOC.NAME = 'FARGO'
AND MEANS2.YEAR IN ('2015','2016','2017'))
ORDER BY TRAITS.TBFLD_NAME