MySQL Forums
Forum List  »  Newbie

Re: Voting SQL
Posted by: Jassim Rahma
Date: February 28, 2022 03:13PM

This is my update SQL

SELECT nuwab.nuwab_id, nuwab.nuwab_uuid, nuwab.nuwab_name,
nuwab.governorate, nuwab.area, IFNULL(nuwab_votes.vote_rating, 0) AS rating
FROM nuwab
LEFT JOIN nuwab_votes ON nuwab_votes.nuwab_id = nuwab.nuwab_id
LEFT JOIN oneid.users ON oneid.users.user_id = nuwab_votes.user_id
GROUP BY nuwab.nuwab_id
ORDER BY nuwab.nuwab_name;


The problem is that the above will just JOIN the tables regardless of the user and what I want to to show the data from nuwab_votes only for user_id = param_user, however if I do this:

SELECT nuwab.nuwab_id, nuwab.nuwab_uuid, nuwab.nuwab_name,
nuwab.governorate, nuwab.area, IFNULL(nuwab_votes.vote_rating, 0) AS rating
FROM nuwab
LEFT JOIN nuwab_votes ON nuwab_votes.nuwab_id = nuwab.nuwab_id
LEFT JOIN oneid.users ON oneid.users.user_id = nuwab_votes.user_id
WHERE nuwab_votes.user_id = param_user
GROUP BY nuwab.nuwab_id
ORDER BY nuwab.nuwab_name;

it will only list the rows inside the nuwab_votes, for example my nuwab is 40 rows and if the user rated 21 then it will only show the 21 where there are other 19 which he did not rate for them but I still want to show then but with a null rating here:

IFNULL(nuwab_votes.vote_rating, 0) AS rating

Options: ReplyQuote


Subject
Written By
Posted
February 23, 2022 10:37AM
February 23, 2022 11:31AM
February 23, 2022 12:52PM
February 23, 2022 02:34PM
February 23, 2022 03:59PM
February 23, 2022 04:27PM
February 23, 2022 05:14PM
February 24, 2022 10:04AM
February 24, 2022 04:21PM
February 24, 2022 04:29PM
February 28, 2022 02:47PM
Re: Voting SQL
February 28, 2022 03:13PM
February 28, 2022 05:41PM
March 01, 2022 05:47AM
March 01, 2022 11:22AM
March 01, 2022 12:57PM
March 01, 2022 02:05PM
March 01, 2022 02:29PM
March 01, 2022 03:19PM
March 01, 2022 03:56PM
March 03, 2022 05:39PM
March 03, 2022 05:40PM
March 03, 2022 09:06PM
March 07, 2022 05:11AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.