php database phpmyadmin without a value

Hi, I have a phpmyadmin question:

I have 2 tables:

table 1:

hfw_post_notif_sub_cat:

id   |    cat_id
1    |    150
1    |    155
1    |    350
2    |   101
2    |   104

table 2
hfw_post_notif_subscriber:
id    |  first_name
1     |   Ron
2     |   Jan

I want a database selection to do this:
If  "cat_id" is not  "350"  then  I get    "first_name" = Jan.

This is what I have, What I get with this is a list with Ron and Jan.

$q = "SELECT hfw_post_notif_subscriber.id, hfw_post_notif_subscriber.first_name, hfw_post_notif_sub_cat.cat_id FROM hfw_post_notif_subscriber, hfw_post_notif_sub_cat WHERE hfw_post_notif_subscriber.id = hfw_post_notif_subscriber.id GROUP BY hfw_post_notif_subscriber.id";
$sth = $db->prepare($q);
$sth->execute();
?>
<html>
      <head>
            <link href="style.css" rel="stylesheet" type="text/css" media="screen" />
      </head>
      <body>
            <h1>Lijst alle klanten</h1>

      
            <table class="lijst">
                  <tr>
                        <th align="right">ID</th>
                        <th align="left">Naam</th>
                        <th align="left">Actie</th>
                  </tr>
                  <?php
                        while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
                              ?>
                                    <tr>
                                          <td align="right"><?php echo $row["id"]; ?></td>
                                          <td width="50%"><?php echo $row["first_name"]; ?></td></tr>
      
-------------------------------------------------------------------------------------------------------------------------------------------------------
I hope someone can help me to take care of the following:

I want a list with the "first_name" except when "cat_id = 350".
In this case only "Jan"
Ron BaasDirecteurAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gr8gonzoConsultantCommented:
What happens when there are 3 or more people? For example:

hfw_post_notif_sub_cat:

id   |   cat_id
1    |   150
1    |   155
1    |   350
2    |   101
2    |   104
3    |   110

hfw_post_notif_subscriber:
id    |  first_name
1     |   Ron
2     |   Jan
3     |   Henry

Open in new window


If cat_id is NOT 350, do you want both Jan AND Henry?

It's a little unusual to do a NEGATIVE query (show me everyone who DOESN'T match this selection), so I want to make sure that I'm understanding your situation correctly.
0
Ron BaasDirecteurAuthor Commented:
Hi gr8gonzo

Yes, thats correct,  I want both Jan ANd Henry
0
gr8gonzoConsultantCommented:
Okay, so here's the raw query:

SELECT ...your desired fields... 
FROM hfw_post_notif_subscriber 
WHERE hfw_post_notif_subscriber.id NOT IN 
  (SELECT id FROM hfw_post_notif_sub_cat WHERE cat_id=350)

Open in new window

Just substitute in your variables.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ron BaasDirecteurAuthor Commented:
Fantastic gr8gonzo,

it works great!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.