php/ mysql/ sql/ inner-join
I have this two columns:
The first column name is TAGS and the second column name is PORTTAG.
I want to get all tags.nome that are not to be used on porttag.tag with porttag.port = 1
$mysqli->query("SELECT nome FROM tags INNER JOIN porttag ON porttag.tag != tags.nome WHERE porttag.port = '".$_GET['edit']."'");
But without success!
Can you help me?
It seems as though you need to use the not exists
operator:
SELECT nome
FROM tags t
WHERE NOT EXISTS (SELECT *
FROM porttag p
WHERE p.tag = tags.nome AND p.port = 1)
I want to get all tags.nome that are not to be used on porttag.tag with porttag.port = 1
This makes me think of this:
select t.*
from tags t
where not exists (select 1 from porttag pt where pt.port = 1 and pt.tag = t.nome);
However, you have something very strange in your data model. The link between the tables should be based on the id not the name.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.