Jump to content

A better way to get MYSQL result??


hjshy

Recommended Posts

I'm sure there must be a better way to get the results I'm after then what I've done...

 

I want the query to select the s_id and s_email fields from table 'subscribers', then to cross check the table 'Newsletter_Subscribers' to make sure the s_id does not appear in there and count how many results there are.

 

  $query1 = mysql_query("SELECT s_id, s_email FROM subscribers" );
  while($qry1 = mysql_fetch_array($query1)) { 

     $query2 = mysql_query("SELECT * FROM Newsletter_Subscribers
                                          WHERE id_subscriber<>".$qry1['s_id'] )  ;
  }

 

I apologise if this is painful to the eye, everything's self taught, so any advice would be really appreciated.

 

 

(MySQL version: 5.0.92)

Link to comment
Share on other sites

Hi

 

Further to the above, if you want the counts then something like this:-

 

SELECT subscriber.s_id, subscribers.s_email, COUNT(Newsletter_Subscribers)
FROM subscribers 
INNER JOIN newsletter_subscribers 
ON newsletter_subscribers.id_subscriber != subscribers.s_id
GROUP BY subscriber.s_id, subscribers.s_email

 

Although logically it seems strange. You appear to be getting a list of subscribers and then getting a count of all the newsletter subscribers who are not that subscriber.

 

All the best

 

Keith

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.