If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Need to get records from first table

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-18-10, 03:02
shahnawaz_rao shahnawaz_rao is offline
Registered User
 
Join Date: Jun 2009
Posts: 1
Post Need to get records from first table

I have two tables user_registration and user_subscription, first users get registers on the site and information goes into first table user_registration. Secondly users are made paid subscribers and the information goes into 2nd table user_susbscriptions.

Now i need a MySql query to fetch emails etc from table 1 who are just registered users not subscribed. How i can exclude the users who are subscribed and their user id exist in table 2. user id is foreign key in table 2.
How i can fetch the emails from table 1 who are just registers not subscribed. Please help me to make a query.

Thanks,
Shahnawaz
Reply With Quote
  #2 (permalink)  
Old 03-18-10, 09:29
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,084
use a LEFT OUTER JOIN together with an IS NULL check on the joined column of the right table (to find the unmatched rows of the left table)
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-18-10, 10:07
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 779
Or a NOT EXISTS/NOT IN subquery.

Dave
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On