从一个查询到另一个查询选择结果

时间:2021-06-20 08:03:39
SELECT id FROM table1 WHERE name LIKE 'test%'; 

That would show me all the ids in table1 with the id of anything that matched test%. So I have been doing this the long way doing this :

这将向我显示table1中的所有ID,其中包含与test%匹配的任何内容。所以我一直这样做:

SELECT * FROM table2 WHERE id = '1011';

Is there anyway to make my table1 query jump and auto insert to WHERE id = '1011', I'd like it to auto match it up whats in query one to query two. Instead of having to run the second query over and over again and get all the results faster.

反正有没有让我的table1查询跳转并自动插入到WHERE id ='1011',我希望自动匹配它在查询一中查询两个。而不是必须一遍又一遍地运行第二个查询,并更快地获得所有结果。

1 个解决方案

#1


0  

You want to do a JOIN:

你想做一个加入:

SELECT a.*
FROM table2 a
JOIN table1 b
  ON a.id = b.id
WHERE b.name LIKE 'test%'

#1


0  

You want to do a JOIN:

你想做一个加入:

SELECT a.*
FROM table2 a
JOIN table1 b
  ON a.id = b.id
WHERE b.name LIKE 'test%'