java - Mysql多条件批量查询
怪我咯
怪我咯 2017-04-18 09:35:24
0
6
987

请教一个问题:mysql中,我查询语句
select * from tableA where name='test' and age='18';
然后我有一个name和age的list列表,分别通过这两个条件去查询,有什么比较方法可以查询;

eg:
select * from tableA where name='test' and age='18';
select * from tableA where name='test1' and age='18';
select * from tableA where name='test2' and age='20';
select * from tableA where name='test2' and age='56';
···

其中查出来的数据对应Java的一个实体。其中List表的大小为500-3000,数据表的记录为每天8万左右

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(6)
左手右手慢动作

Create a view query, which will be more efficient. At least slightly faster than temporary tables

巴扎黑

table A adds a column named nameage. The value in it is the combination of name and age. For example, test18
select * from tableA where nameage in ('test18','xxxxxx','xxxxxxx')

Of course you don’t need to add columns, you can also write it in SQL yourself

小葫芦

togeek’s answer is very cool
You may want to consider the efficiency of sql again

巴扎黑
select a.* 
from tableA a
inner join list l on l.name=a.name and l.age=a.age

No way?

黄舟

When the amount of data is not large, you can do this.

SELECT * FROM tableA
WHERE (name, age) IN (
('test', 18),
('test1', 18),
('test2', 20),
('test2', 56))

But by explaining the above query, you will find that this way of writing cannot use the index, so the query efficiency is very low.

伊谢尔伦
select * from tableA where (name='test'and age='18')
or (name='test1'and age='18')
or (name='test2'and age='20')
...

Create a temporary table and join 2 fields in the temporary table

http://stackoverflow.com/ques...

http://www.zhihu.com/question...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template