Forum Moderators: open

Message Too Old, No Replies

Distinct values from two tables

         

a_angova

7:26 pm on Aug 14, 2006 (gmt 0)

10+ Year Member



Hello,

I have one sql:
SELECT b.id FROM transactions a, members b WHERE a.UserID=b.UserID AND a.SiteID=b.SiteID

and another:
SELECT MemberID as id FROM questionnaire

How can I get the distinct values from them in mysql?

Thank you, Ani

FalseDawn

7:39 pm on Aug 14, 2006 (gmt 0)

10+ Year Member



[w3schools.com...]

Or, if you need distinct values for each query separately (it's not clear what you are after), use the DISTINCT keyword.

[edited by: FalseDawn at 7:41 pm (utc) on Aug. 14, 2006]

a_angova

7:45 pm on Aug 14, 2006 (gmt 0)

10+ Year Member



Actually I need to take all b.id from the first statment that are not contained into the secnd table ad MemberID.

Thank you, Ani

a_angova

7:46 pm on Aug 14, 2006 (gmt 0)

10+ Year Member



Actually I need to take all b.id from the first statement that are not contained into the second table as MemberID.

Sorry for the spelling mistakes...

Thank you, Ani

a_angova

8:43 pm on Aug 14, 2006 (gmt 0)

10+ Year Member



Anyone pls help me :(((

FalseDawn

9:10 pm on Aug 14, 2006 (gmt 0)

10+ Year Member



SELECT b.id FROM transactions a JOIN members b ON a.UserID=b.UserID AND a.SiteID=b.SiteID WHERE b.id NOT IN (SELECT MemberID FROM questionnaire)

Or if your SQL does not support subqueries, reformulate as a LEFT JOIN

SELECT b.id FROM transactions a JOIN members b ON a.UserID=b.UserID AND a.SiteID=b.SiteID LEFT JOIN questionnaire q ON b.id=q.MemberID WHERE q.MemberID IS NULL

a_angova

9:46 pm on Aug 14, 2006 (gmt 0)

10+ Year Member



Hello,
Upon running:
SELECT b.id FROM transactions a JOIN members b ON a.UserID=b.UserID AND a.SiteID=b.SiteID LEFT JOIN questionnaire q ON b.id=q.MemberID WHERE q.MemberID IS NULL

I get :

#1064 - You have an error in your SQL syntax near 'ON a.UserID=b.UserID AND a.SiteID=b.SiteID LEFT JOIN questionnaire q ON b.id=q.M' at line 1

Can you advise, thank you :(

FalseDawn

4:57 am on Aug 15, 2006 (gmt 0)

10+ Year Member



it's probably a bracketing issue, try:

SELECT b.id FROM ((transactions a JOIN members b ON a.UserID=b.UserID AND a.SiteID=b.SiteID) LEFT JOIN questionnaire q ON b.id=q.MemberID) WHERE q.MemberID IS NULL