0
\$\begingroup\$

Is there any way to write this query in a better way than this if I want to insert postid from posts table to star_ratings table if the postid is not exists in star_ratings table?

INSERT INTO star_ratings(post_id) 
SELECT postid FROM posts 
WHERE type in ('D', 'B') 
AND postid NOT IN (SELECT post_id FROM star_ratings) 
ORDER BY postid ASC
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.