0

I've a project where I submitted all the records to notification table, now I want to fetch according to the session_id's activity

Details: My project is Q&A question and answer platform, I've separate tables in my database for each activity. e.g, questions, answers, question-upvote, answers-like, comments, comments-like, etc. I also have a table for notifications, where there are 7 - Columns exist. id, date, byUser_id, source_id, alert, source_type, and status.

Notifications Structure - Image Attached: enter image description here

Now after insert records in notifications table, I want to fetch the records according to the session_id's content (if someone liked the session_id's answer, how to fetch? That is my question.

Trying Query:

SELECT id,byUser_id,source_id,alert,source_type
FROM `qa-notifications`
FULL JOIN `qa-questions` `qa-notifications`.`source_id` = `qa-questions`.`id`
WHERE `qa-question`.`user_id` = '".$_SESSION['id']."'";
Sami Ullah
  • 129
  • 9
  • It sounds like you are asking how to write a SQL query to return the results you need; if that is true, you should post the SQL table schema/definitions in Text format. – Aron Jul 14 '21 at 14:03

1 Answers1

0

By all means, i am no expert, but i'm trying to think along.

If i understand correctly, you want to fetch the last action done ( liked, replied etc)

in that case, you need to select the last row in the notifications table:

SELECT * FROM Table ORDER BY ID DESC LIMIT 1 (How to select the last record of a table in SQL?) from there on out, fetch the data from the other tables with a JOIN.

Yet again, no expert on the case, post intended to help you progress to the solution.

FlipLucky
  • 23
  • 6