I'm trying to INSERT some data into a table but only when the subquery COUNT is > 0.
This is what I have so far.
INSERT INTO users_friends (userId, friendId) VALUES (77, 100)
WHERE
(SELECT COUNT(id) FROM users WHERE email = 'a@g.com') > 0
Both queries work independently FYI.
This should be a simple fix hopefully. Cheers
Try this::
SQLFiddle demo if there are records 'a@g.com'
SQLFiddle demo if there are NOT records 'a@g.com'
Another way would be: