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 9126863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:08:59+00:00 2026-06-17T07:08:59+00:00

I have a pretty huge SQL query to check for notifications, and I have

  • 0

I have a pretty huge SQL query to check for notifications, and I have several different types of notifications in the table, IE: posts, likes, comments, photoComments, photoLikes, videoLikes, etc. (Always adding more to it) And I have come into a problem, I’m not really sure how to best do this anymore. Thus far the way I have done it is working perfectly, and really quite easy to add to, however this one notification Type I have to check more than just one other table, I have to check two others and I haven’t been able to get it to work.

So here it is: (This is only one part of my huge query, the only relevant part really)

n.uniqueID = ANY (
              SELECT photos.id
              FROM photos INNER JOIN posts ON (photos.id=posts.post)
              WHERE photos.state=0
              AND posts.state=0 
              AND posts.id = ANY (
                                   SELECT likes.postID FROM likes
                                   INNER JOIN posts ON (posts.id=likes.postID)
                                   WHERE likes.state=0 AND posts.state=0
                                  )
                )

So basically all I really need to do is check the state columns in each table because that says whether or not it is deleted or not (if it’s not 0 then it’s deleted and shouldn’t be returned)
So it would be like:

IF photos.state=0 AND posts.state=0 AND likes.state=0 return it.

  • n.uniqueID, posts.post, and photo.id will all be the same
    value.
  • posts.id and likes.postID will also be the same value.

My issue is that it doesn’t seem to be checking the likes.state, I don’t think.

  • 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-06-17T07:09:00+00:00Added an answer on June 17, 2026 at 7:09 am

    I think you just want to join the three tables together in a single query:

    n.uniqueID = ANY (
                  SELECT photos.id
                  FROM photos INNER JOIN
                       posts
                       ON photos.id=posts.post inner join
                       likes
                       on posts.id = likes.postId
                  WHERE photos.state=0 and
                        posts.state=0 and
                        likes.state = 0
                      )
    

    Your logic is not to return when there is a like or post with the state of 0. It seems to be that all the likes and posts have a state of zero. For this, do an aggregation with a having clause:

    n.uniqueID = ANY (
                  SELECT photos.id
                  FROM photos INNER JOIN
                       posts
                       ON photos.id=posts.post inner join
                       likes
                       on posts.id = likes.postId
                  where photos.state = 0
                  group by photos.id
                  having MAX(posts.state) = 0 and MAX(likes.state) = 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is giving me headaches. I have a Word macro that is pretty huge.
I have a huge table which I need to read through on a certain
I have an Iphone Project - Pretty huge Project and I cant startover. I
I have a script, that's pretty huge for an actual simple task, because it's
I have a project that implemented Linq To SQL, and I was pretty happy
In my app, I have a pretty huge datamodel and its .sqlite data file.
I have pretty simple jquery code : $(document).ready(function(){ $('img.marqFl').on({ mouseenter: function() { $(this).animate({height: 300},
I have pretty good skills in PHP , Mysql and Javascript for a junior
i have pretty simple simple question (i hope so). How do i change the
I have pretty standard Qmail toaster installation. I'm using the dot files to set

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.