简体   繁体   English

MYSQL PHP内连接比较不同的值

[英]MYSQL PHP Inner Join Compare different values

I have this two columns: 我有这两列:

在此输入图像描述

The first column name is TAGS and the second column name is PORTTAG. 第一列名称为TAGS,第二列名称为PORTTAG。

I want to get all tags.nome that are not to be used on porttag.tag with porttag.port = 1 我想获得所有不在porttag.tag上使用的tag.nome和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: 好像你需要使用not exists运算符:

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 我想获得所有不在porttag.tag上使用的tag.nome和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. 表之间的链接应该基于id而不是名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM