Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7092859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:22:01+00:00 2026-05-28T08:22:01+00:00

I’m a little stuck with an sql query. I’ve searched everywhere but to no

  • 0

I’m a little stuck with an sql query. I’ve searched everywhere but to no avail so was hoping somebody here could help.

I have 2 tables.

Table 1 is a list of notifications with the following columns

  • notification_id (this is the auto incremented primary key)
  • notification (This is the notification message)
  • from_id (This is the user_id of the person sending the notification)

eg.

|  notification_id  |  notification  |  from_id  |
|       25          |  this message  |    7      |
|       26          |  that message  |    8      |

Table 2 shows which users have read each notification. It has the following columns

  • notification_id (this is the id of the relevant notification)
  • user_id (This is the user id of the person who has read the notification)

eg.

| notification_id   |   user_id   |
|     25            |      1      |
|     25            |      2      |
|     25            |      3      |
|     26            |      2      |

The tables are joined on notification_id and we have a one to many relationship as many users will read each notification.

What I am trying to do is query the database to return all the notifications that the particular user has not already read. In other words I want the data from table one but only if table 2 doesn’t have an entry where user_id is (My user_id x) for the corresponding notification_id.

So if my user_id is 4 then I get the data for both notification_id 25 and 26 as user_id 4 is not listed in table 2 for either of those

If my user_id is 2 I don’t get any data as user_id 2 is listed in table 2 as having read both notification_id 25 and 26

If my user_id is 1 I get the data for notification_id 26 but not 25

I originally thought I could use this

SELECT
    notification_id, notification, from_id 
FROM table_1 
INNER JOIN table 2 
    ON table_1.notification_id = table2.notification_id
WHERE table2.user_id != X

But this is actually a long way off what I need and I’ve reached a bit of a dead end.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:22:02+00:00Added an answer on May 28, 2026 at 8:22 am

    I would do a left join and look for empty joins.

    SELECT notification_id, notification, from_id FROM table_1
    LEFT JOIN table_2 ON table_2.notification_id = table_1.notification_id AND table_2.user_id = x
    WHERE table_2.notification_id IS NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.