ã¿ãããªãã¼ãã«ããã(x, 1), (x, 2)ãã¨ãã«å«ããããªxãå ¨åæããSQLæã¯?ã£ã¦è©±ã«ã 1. (SELECT DISTINCT a FROM hoge WHERE b = 1) INTERSECT (SELECT a FROM hoge WHERE b = 2); åé¡ã®å®ç¾©ã«å¿ å®ãMySQLã¨ãã ã¨INTERSECTã«å¯¾å¿ãã¦ãªãã®ãé£ç¹ãå é¨çã«ã¯ãã¼ãã«ã段éçã«å°ãããã¦ããã®ããªã¼ã 2. SELECT DISTINCT t1.a FROM hoge t1, hoge t2 WHERE t1.a = t2.a AND t1.b = 1 AND t2.b = 2; 1åä¸ã®SQLæããINTERSECTã使ããªãããã«ãã¾ãããæããINNER JOINãå é¨ã§ã©ããã£ã¦ããã¯ç¥ããªããã©ããã£ã¨ANDãè¦ãªããå¦çãã¦ããããã1.ããéãããããªãããªã¼ã¨æã
{{#tags}}- {{label}}
{{/tags}}