[英]SQL select from table where multiple entries exist
I have a database of info from the pokemon games.我有一个来自口袋妖怪游戏的信息数据库。 One of the tables contains the moves that can be learned by each pokemon.其中一张表包含每个口袋妖怪可以学习的动作。 How can I select from this table where a pokemon can learn both of two moves?我怎样才能从这张表中的 select 口袋妖怪可以同时学习两个动作?
My current query is SELECT * FROM 'learned-moves' WHERE 'Version Group'=? AND ('Move'=? OR 'Move'=?);
我当前的查询是SELECT * FROM 'learned-moves' WHERE 'Version Group'=? AND ('Move'=? OR 'Move'=?);
SELECT * FROM 'learned-moves' WHERE 'Version Group'=? AND ('Move'=? OR 'Move'=?);
but this selects all rows that contain either move.但这会选择包含任一移动的所有行。 How can I only return those rows if they both match?如果它们都匹配,我怎样才能只返回这些行?
Consider an INNER JOIN
on itself or self-join:考虑自身的INNER JOIN
或自连接:
SELECT l1.Pokemon, l1.'Move' AS 'Move1', l2.'Move' AS 'Move2'
FROM 'learned-moves' l1
INNER JOIN 'learned-moves' l2
ON l2.Pokemon = l1.Pokemon
AND l2.'Version Group' = l1.'Version Group'
AND l1.'Version Group' = ?
AND l1.'Move' = ?
AND l2.'Move' = ?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.