I’m trying to select data from one table ONLY IF there is no data within the other table for the user and site.
This is what I have so far.
SELECT
l.link_id,
l.link_name,
l.link_points,
l.link_time,
COUNT(uc.user_id) AS clicks
FROM
links AS l LEFT OUTER JOIN
(SELECT user_id, site_id FROM user_clicks WHERE site_id = l.link_id AND user_id = ".$user['user_id'].") as uc
USING (link_id)
GROUP BY
l.link_id
Which is my current attempt at it but I get “Unknown column ‘l.link_id’ in ‘where clause'” when trying to pull that data in the outer join.
How do I go about this?
This here should work:
The LEFT JOIN selects everything from table
linksand with theuc.site_id IS NULLin theWHEREclause you make sure, that there is no row in the other table. Actually it’s not important which column you name there, as long as it’s fromuser_clicks