Solved

Query question

Posted on 2012-04-03
11
334 Views
Last Modified: 2012-06-04
I have this query:

SELECT
    pd.person_id, pd.first,pd.email
FROM
    pd
INNER JOIN
    srf ON pd.person_key = srf.person_key
WHERE
    srf.survey_option_key IN (297,298,299)
AND
    srf.survey_question_key = '43'
AND
    pd.is_subscriber ='1'
ORDER BY
    pd.person_id ASC;

Open in new window


I would like to also grab data from a column called "option_text" in the sod table. I am having trouble figuring out how to join

sod.option_text ON sod.survey_option_key =  srf.survey_option_key and display the results . Any ideas?
0
Comment
Question by:lvollmer
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 24

Expert Comment

by:johanntagle
ID: 37803763
Should just be:

SELECT
    pd.person_id, pd.first,pd.email,sod.option_text
FROM
    pd
INNER JOIN
    srf ON pd.person_key = srf.person_key
INNER JOIN
    ON srf.survey_option_key =  sod.survey_option_key
WHERE
    srf.survey_option_key IN (297,298,299)
AND
    srf.survey_question_key = '43'
AND
    pd.is_subscriber ='1'
ORDER BY
    pd.person_id ASC

Open in new window


Or maybe you need LEFT OUTER JOIN instead of INNER JOIN, in case the entry on sod is optional.
0
 

Author Comment

by:lvollmer
ID: 37806924
I had previously tried your solution and when I do, i get a message :

Table 'sod.option_text' doesn't exist

and it does , in fact, exist.
0
 
LVL 24

Expert Comment

by:johanntagle
ID: 37808349
sorry typo.  line 8 above should be "sod ON srf.survey_option_key = sod.survey_option_key"
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 

Author Comment

by:lvollmer
ID: 37812713
yeah I had caught that and fixed it but still got that error.
0
 
LVL 24

Expert Comment

by:johanntagle
ID: 37814281
Odd.  Can you share a dump of the tables so I can test it from my end?
0
 
LVL 9

Accepted Solution

by:
keyu earned 500 total points
ID: 37822525
SELECT
    pd.person_id, pd.first,pd.email,sod.option_text
FROM
    pd,sod
INNER JOIN
    srf ON pd.person_key = srf.person_key
WHERE
    srf.survey_option_key IN (297,298,299)
AND
    srf.survey_question_key = '43'
AND
    srf.survey_option_key =  sod.survey_option_key
AND
    pd.is_subscriber ='1'
ORDER BY
    pd.person_id ASC
0
 
LVL 32

Expert Comment

by:awking00
ID: 37824799
Is sod table in same schema as pd and srf?
0
 

Author Comment

by:lvollmer
ID: 37828907
I believe so,

PD and SRF share  a unique key that I am able to join on,  sod does not have that same key, but it does have a key that matches up with SRF

IE:

PD & SRF share "person_id"

SRF & SOD share "survey_option_key"
0
 
LVL 32

Expert Comment

by:awking00
ID: 37828986
Can you do a describe of the sod table (i.e. column names and datatypes)?
0
 

Author Comment

by:lvollmer
ID: 37828989
it will take me a bit but I will get this info and upload it
0
 
LVL 9

Expert Comment

by:keyu
ID: 37831910
I have tried my posted query and uts working exactly as you want can you please comment something on this
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mysql query for sum() 3 28
Need return values from a stored procedure 8 21
SQL Recursion 6 20
add criteria to query in VB, Access 2003 2 10
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question