Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
你好我对mysql中的嵌套选择有疑问。我想要一个可以实现以下虚拟查询打算实现的目标的工作查询:
select t1.col1 from t1 where t1.col2 in (select t3.col2, t3.col3 from t3 order by t3.col3 limit NUM)
好吧,基本上来说,t1.col2 应该在嵌套选择 t3.col2 中,但是嵌套选择应该按另一列 t3.col3 排序。
不幸的是,MySQL不支持LIMIT与IN.
MySQL
LIMIT
IN
尝试这个:
SELECT col1 FROM ( SELECT DISTINCT col2 FROM ( SELECT col2 FROM t3 ORDER BY col3 LIMIT 5 ) q ) q JOIN t1 USING (col2)