Blog BlogArticle Article
---- ----------- -------
id
id------blog_id -id
title article_id_/ title
To be clear, the relation is:
Blog.id HAS_MANY BlogArticle.blog_id
Article.id HAS_MANY BlogArticle.article_id
My question is, may i get Article.id that never been linked to Blog.id without use WHERE NOT IN clause? because i think it (WHERE NOT IN) will impact database server performace when we use it for a really big list (cmiiw)
I’m sorry for my english, but i mean with specified blog_id, so lemme explain, in example, i have 2 blogs and 7 articles rows, each blog shouldn’t have duplicate article but allowed to have same articles against others.
i just afraid if my english cant tell you what i mean so this is the SQL if use WHERE NOT IN
SELECT *
FROM `article`
WHERE `article`.`id` NOT IN (
SELECT CONCAT( `blog_article`.`article_id` )
FROM `blog_article`
WHERE `blog_article`.`blog_id` =1
)
Yeah that’s how I’d do it and if you take a look around I would say that the consensus is that the way you’ve done it is the “proper way”, sorry I wasn’t more helpful I wasn’t completely clear on what you wanted to do. Not sure I understand why you are performing a string concatenation on that id however.