join - MySQL query to select distinct values from one table and all values from a separate table -
i have 2 tables surveys. table 1 contains surveys sent out following fields: sid,salesrep,location. table 2 contains survey results returned following fields: rid,sid,qid,aid.
in table 1, sid unique, , there no duplicates. in table 2, rid unique, , represents each question answered, , answer. sid in table 2 represents survey questions have been answered. so, if there 10 questions answered on survey, there 10 rows in table 2 same sid.
what need find out how many surveys have been sent , how many taken each sales person. can use 2 queries find information separately:
- select * table1
- select distinct table2.sid, table1.salesrep,table1.location table2 inner join table1 on table1.sid = table2.sid
what have 1 query give me both results. i'm assuming take kind of outer join since there more results table1 table2 because don't 100% return on surveys. however, when try run outer join, locks , returns nothing. these tables aren't large @ point.
can please point me in right direction? possible?
you have't specified enough result understand,you may try hope works
select * table1
sid in (select distinct sid table2)
if doesn't works please specify well
Comments
Post a Comment