简体   繁体   English

SQL select 来自存在多个条目的表

[英]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?如果它们都匹配,我怎样才能只返回这些行?

edit:编辑: 数据库架构

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.

相关问题 Oracle SQL:将选择从一个表插入到另一个表中,其中用户具有带有订单号的多个条目 - Oracle SQL: Insert select from one table to another where user has multiple entries with order number 嵌套SQL查询,其中一个表中的ID与另一个存在两个特定条目的表匹配 - Nested SQL Query where id from one table matches to another table where two specific entries exist SQL:从用户其他表中不存在的表中选择 - SQL: select from table where it doesnt exist in other for a user 获取一个表的所有行,并从另一个表中匹配行,其中SQL中可能不存在条目 - Getting all rows of one table, and matching rows from another table where entries may not exist in SQL 如何从表中选择存在多行的单行 - How to select a single row where multiple rows exist from a table SQL:选择其他表中不存在的位置 - SQL: Select where doesnt exist in other table 从两个ID都存在的表中选择 - select from table where both id exist 从SQL表中选择行,其中所有参数集都存在于联接表中 - Select rows from SQL table where ALL of a set of parameters exist in joined table SQL从一张表中选择具有相同ID的多个条件 - SQL select where multiple condition by same id from one table SQL:Select 表中特定字段集重复的所有条目 - SQL: Select all entries where a particular set of fields is duplicated in the table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM