2

我已经尝试了所有,还有另一种可以工作的语法吗?我有以下

SELECT  `ID` , `Home_Team`
FROM  `FixturesDates` where `ID` =
  (SELECT `ID` 
   FROM `FixturesDates` 
   WHERE `Home_Team`     
      REGEXP 'saturday|sunday|monday|tuesday|wednesday|thursday|friday' 
   order by ID asc LIMIT 1)

这有效,

我也有

SELECT  `ID` , `Home_Team`
FROM  `FixturesDates` 
where `ID` =
  (SELECT `ID` FROM `FixturesDates` WHERE `Home_Team`
   REGEXP 'saturday|sunday|monday|tuesday|wednesday|thursday|friday' 
   order by ID asc LIMIT 1,1) 

这也有效,但我无法将两者结合在一起,已经尝试过

SELECT  `ID` , `Home_Team`
FROM  `FixturesDates` 
where `ID` =
  (SELECT `ID` FROM `FixturesDates` WHERE `Home_Team`
   REGEXP 'saturday|sunday|monday|tuesday|wednesday|thursday|friday' 
   order by ID asc LIMIT 1)
UNION
  (SELECT `ID` FROM `FixturesDates` WHERE `Home_Team`
   REGEXP 'saturday|sunday|monday|tuesday|wednesday|thursday|friday' 
   order by ID asc LIMIT 1,1) 

但这不起作用,AND 或 OR 也不起作用。还有其他的吗?

谢谢

4

1 回答 1

0

您不能将它们组合起来,因为它们具有不同的列。

尝试将NULLor添加Home_Team到第二个子查询:

SELECT  `ID` , `Home_Team`
FROM  `FixturesDates` 
where `ID` =
  (SELECT `ID` FROM `FixturesDates` WHERE `Home_Team`
   REGEXP 'saturday|sunday|monday|tuesday|wednesday|thursday|friday' 
   order by ID asc LIMIT 1)
UNION
  (SELECT `ID`, NULL as Home_Team FROM `FixturesDates` WHERE `Home_Team`
   REGEXP 'saturday|sunday|monday|tuesday|wednesday|thursday|friday' 
   order by ID asc LIMIT 1,1) 

或者,更简单地说:

SELECT  `ID` , `Home_Team`
FROM  `FixturesDates` 
where `ID` in
  (SELECT `ID` FROM `FixturesDates` WHERE `Home_Team`
   REGEXP 'saturday|sunday|monday|tuesday|wednesday|thursday|friday' 
   order by ID asc LIMIT 2)

这是基于相同的查询。也许你的意思是这样的:

SELECT  `ID` , `Home_Team`
FROM  `FixturesDates` 
where `ID` =
  (SELECT `ID` FROM `FixturesDates` WHERE `Home_Team`
   REGEXP 'saturday|sunday|monday|tuesday|wednesday|thursday|friday' 
   order by ID asc LIMIT 1)
  OR ID = 
  (SELECT `ID`, NULL as Home_Team FROM `FixturesDates` WHERE `Home_Team`
   REGEXP 'saturday|sunday|monday|tuesday|wednesday|thursday|friday' 
   order by ID asc LIMIT 1,1) 

您的两个原始查询的正确联合将包括两个完整查询:

SELECT  `ID` , `Home_Team`
FROM  `FixturesDates` where `ID` =
  (SELECT `ID` 
   FROM `FixturesDates` 
   WHERE `Home_Team`     
      REGEXP 'saturday|sunday|monday|tuesday|wednesday|thursday|friday' 
   order by ID asc LIMIT 1)
union 
SELECT  `ID` , `Home_Team`
FROM  `FixturesDates` 
where `ID` =
  (SELECT `ID` FROM `FixturesDates` WHERE `Home_Team`
   REGEXP 'saturday|sunday|monday|tuesday|wednesday|thursday|friday' 
   order by ID asc LIMIT 1,1) 
于 2013-04-27T16:46:57.040 回答