2017-06-22 87 views
-2

我的第一次表t1有列:與條件在其他表中選擇從表列

t_id, c_id, town 

我的第二個表t2有列:

p_id, year_of_birth, t_id -- < is ref to t_id in 1st table 

我想是這樣的(僞代碼) :

SELECT year_of_birth from 2st where 
(
(t_id from 2st) = t_id from 1st) AND (c_id from 1st) = 'text value' 
) 
; 

這將如何在SQL中工作?

回答

0

使用普通INNER JOIN

SELECT t2.year_of_birth 
FROM t1 
JOIN t2 USING (t_id) 
AND t1.c_id = 'text value'; 

Basics in the manual.