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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:34:48+00:00 2026-06-09T09:34:48+00:00

I have a need to build a MySQL query to notify users of a

  • 0

I have a need to build a MySQL query to notify users of a software package when a comment is added to a post. The tables I have for this are

Posts: pid, uid

Comments: cid, uid, pid

Users: uid

Related: rid, uid1, uid2

Devices: did, uid

A post can have many comments, many comments can be posted per user, and a user may have many devices.

When a comment is inserted I need to get a list of unique devices for everyone who has contributed to the comments for the moment including the author but only where they are related to the user who has commented.

the

redlated.uid1

holds the userid and

related.uid2

holds their related userid e.g.

-----------------------------------
| rid       |  uid1      |  uid2  |
-----------------------------------
| 1         |  34        |  43    |
-----------------------------------
| 2         |  43        |  34    |
-----------------------------------

I have available the following data

PostAuthorId | PostID | UserID

Can anyone help I am struggling to get the right data out all queries thus far have been wrong, i have not posted one as I think it could confuse even further.

As i said I need to return only unique devices, any help would be awesome thanks

EDIT SQLFIDDLE **

http://sqlfiddle.com/#!2/4217f


  • 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-09T09:34:49+00:00Added an answer on June 9, 2026 at 9:34 am

    All you need is one correct (multi) JOIN

    SELECT ...
    FROM Posts P
    INNER JOIN Users O ON P.uid = O.uid  -- Post owner
    INNER JOIN Devices OD ON O.uid = OD.uid  -- Devices of post owner
    INNER JOIN Related R ON O.uid = R.uid1  -- Post owner to other user relationship
    INNER JOIN Comments C ON R.uid2 = C.uid AND P.pid = C.pid  -- Comments by related user
    INNER JOIN Devices CD ON C.uid = CD.uid  -- Devices of users posting comments
    WHERE pid = yourPostID
    

    this should do it.
    Don’t forget that you have Devices table twice so you have to refer to them via OD (owner’s) and CD (comment poster’s) devices

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 4 MySQL tables folder, folder_users, folder_posts, posts I need to build a
I have a need to build the data string dynamically. This is not working,
I need to build a dynamic linq query with or operators. I have seen
I need to build an MySQL query and I want to try with django
I need to query a Mysql database with Python. I have virtual env installed
I'm using CodeIgniter 2 (latest build) ...let's say I have this query: $CI->db->select(FileName, GUID,
I need to build a MySQL query that returns only the common columns for
I have a simple mysql query I need to put in my admin. It
Why you may ask? Because i have built the app on mysql and need
(java 1.5) I have a need to build up a String, in pieces. I'm

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.