I am having issues writing this query. I dont know if I should actually use count because that returns the actual count and I want to return people that havent done a review. Anyway here is my query that I am trying to write.
Find those users that haven’t reviewed any businesses.
The tables that I am using are
reviews;
+-------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------+------+-----+---------+-------+
| business_id | int(11) | NO | PRI | NULL | |
| user_id | int(11) | NO | PRI | NULL | |
| review_id | int(11) | NO | PRI | NULL | |
| review_date | date | YES | | NULL | |
| star_rating | int(1) | YES | | 1 |
businesses
+--------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| business_id | int(11) | NO | PRI | NULL | |
| name | varchar(50) | YES | | NULL | |
| city | varchar(40) | YES | | NULL | |
| state | varchar(20) | YES | | NULL | |
| full_address | varchar(120) | YES | | NULL | |
users;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| user_id | int(11) | NO | PRI | NULL | |
| name | varchar(50) | YES | | NULL | |
| user_since | date | YES | | NULL
Here is what I have so far
SELECT reviews.user_id FROM reviews
JOIN businesses ON (reviews.business_id = businesses.business_id)
GROUP BY reviews.user_id ASC
HAVING COUNT(*) > 0;
This returns 0 results and I dont think this is right because someone can be a user and not write a review. But I dont know what else I could. Thanks
EDIT: I figured out that last query but now I am trying to complete this one!
Find the users that have reviewed every business.
ONyou havereviews.business_idtwice. Try switching one tobusinesses.business_idSHOW CREATE TABLE, it is more descriptive thanDESCRIBE TABLE.