lundi 25 juillet 2016

sql join query to check logged-in user liked or not

A query really sucks the whole day:(..I am getting a problem while fetching query result.

Scenario: I have two tables where in first table I saved user activity details and second table is used to saves likes functionality of users of all activities entered by other users.

What I need is that to fetch like value whether current logged in user already liked activity or not. I need some sort of boolean value.

Table to store activities

enter image description here

Table to store like count

enter image description here

What I need to check that distinct activity wise logged-in user like check . Tried Query :

SELECT at.id, CASE WHEN lk.status =1 and lk.user_id = 6 THEN 1 ELSE 0 END AS l FROM activity_transactions at LEFT JOIN likes lk ON at.id = lk.activity_transaction_id

Guys any solution?? The problem is, I am getting duplicate rows. I need to check 1 if users are liked else 0 for other activity rows.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire