1.11M Members

Multiple Column Values in One Query

 
0
 

Hi All,

I'm having a go at SQL queries and have the following:

SELECT     b.vSeries_Table_Number, b.vSeries_Number, b.vSeries_Geography, b.vSeries_Type,b.vSeries_Unit_Type, a.Variable_Date, a.Variable_Value
FROM         tblPopulationSC AS a INNER JOIN
                      tblVSeriesList AS b ON a.vSeries_ID = b.vSeries_ID
                      and b.vSeries_Geography='Manitoba' --and b.vSeries_Unit_Type=' 15 to 64 years'
                      and b.vSeries_Type=' Both sexes'
                      and b.vSeries_Unit_Type=' 65 years and over'

What I want to do is include more than one vSeries_Unit_Type. As you can see I have had to comment out the "15 to 64 years" type in order to have the "65 years and over" type. I want both in one query (as well as others) but when I include both in the query, I get no results back. If I comment out "65 years and over" and then use the "15 to 64 years", the query runs properly. As I said, it won't with both. How can I over come this?

 
0
 

I obviously have a lot to learn with queries. For my problem I created 2 separate views and then a query that includes both views. I don't particularily like the output format but it's a start.

 
0
 

My solution has been to use OR instead of AND like in the following:

SELECT DISTINCT 
                      b.vSeries_Table_Number, b.vSeries_Number, b.vSeries_Geography, b.vSeries_Type, b.vSeries_Unit_Type, a.Variable_Date, a.Variable_Value
FROM         dbo.tblPopulationSC AS a INNER JOIN
                      dbo.tblVSeriesList AS b ON a.vSeries_ID = b.vSeries_ID AND b.vSeries_Geography = 'Manitoba' AND b.vSeries_Type = ' Both sexes' AND 
                      (b.vSeries_Unit_Type = ' 15 to 64 years' OR
                      b.vSeries_Unit_Type = ' 65 years and over')
Question Self-Answered as of 1 Year Ago
 
1
 

You could also write it as:

SELECT DISTINCT 
                      b.vSeries_Table_Number, b.vSeries_Number, b.vSeries_Geography, b.vSeries_Type, b.vSeries_Unit_Type, a.Variable_Date, a.Variable_Value
FROM         dbo.tblPopulationSC AS a INNER JOIN
                      dbo.tblVSeriesList AS b ON a.vSeries_ID = b.vSeries_ID AND b.vSeries_Geography = 'Manitoba' AND b.vSeries_Type = ' Both sexes' AND 
                      b.vSeries_Unit_Type in ( ' 15 to 64 years', ' 65 years and over')
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: