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. 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
.
BUT
I suspect that your problem might be more complex than that, perhaps the sample is too small.
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.