gpt4 book ai didi

mysql - 如何优化我在 Mysql 中连接两个表的查询

转载 作者:行者123 更新时间:2023-12-01 00:45:13 25 4
gpt4 key购买 nike

我的要求如下

SQL1: sel Names, Numbers from Table1 where condition = FilterName

the output of this will be like:
aa,11
bb,22
cc,33

SQL2:我需要这样写一个sql

 Sel * from table2 where condition = 'Something' 
And names & Numbers in ([aa,11],[bb,22],[cc,33])

我把查询写成这样

Select * from table2 where condition = 'SOmething' 
And names in (select Names from Table1 where condi = 'FilterName')
And Numbers in (select Numbers from Table1 where condi = 'FilterName')

还有其他更好的方法来编写这个查询吗?我不能在这里使用程序

最佳答案

您可以在这里尝试使用 JOIN:

Select table2.* from table2
join table1 on table2.names = table1.names and table2.numbers = table1.numbers
where table1.condi = 'FilterName'
and table2.condition = 'Something'

希望对您有所帮助!

关于mysql - 如何优化我在 Mysql 中连接两个表的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22956738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com