简体   繁体   English

mysql-true时查询并不总是显示结果

[英]mysql - query does not always display result when true

I am running the following query in mysql and depending on what value has been added will depend if the system displays a row when I run the query. 我正在mysql中运行以下查询,并且取决于添加的值将取决于我在运行查询时系统是否显示一行。 Each row as a value and this should not be a problem and all values that her in the database should display a row but this is not the case, here is my query. 每行都是一个值,这应该不是问题,她在数据库中的所有值都应显示一行,但事实并非如此,这是我的查询。

If I enter golf the correct row will show but not for football. 如果我进入高尔夫,将显示正确的行,但不显示足球。

CREATE TABLE `sports` (
  `sport_ID` int(11) NOT NULL,
  `Name` varchar(20) NOT NULL,
  `Tag` varchar(100) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;

INSERT INTO `sports` (`sport_ID`, `Name`, `Tag`) VALUES
(1, 'Football', 'Rugby'),
(2, 'Rugby', 'Basketball'),
(3, 'Basketball', 'Golf'),
(4, 'Golf', 'Football')


SELECT *
FROM sports b 
join sports a
on a.Tag = b.Name
where b.sport_ID > a.sport_ID and a.Tag = 'Football'
LIMIT 1

Replace > by <> : >替换为<>

SELECT *
FROM sports b 
left join sports a
on a.Tag = b.Name
where b.sport_ID <> a.sport_ID and a.Tag = 'golf'
LIMIT 1

It returns a row now both for golf and football . 现在无论是golf还是football它都会返回一行。

BUT

I suspect that your problem might be more complex than that, perhaps the sample is too small. 我怀疑您的问题可能比这更复杂,也许样本太小。

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

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