-2

我有两张桌子:

t1:

cust_id        email
201           email1@sadpanda.com
202           email2@email.com
203           email3@sadpanda.com


t2:

cust_id     value
201         dfceaa64f8b93661903a849b09c5ac4e10abdfed21763a04d6eb9523e02d6dc1:Qs
202         c15af11e5acb2f6b7e7b12ab7eee8ce482f0cf76f76b7e65dde6b15c3a910680:Qx
203         71ae98d020b16f6f668db6bde3f9c18350a892b55736995237fa71aa5dc2b206:MU

我想从“t1”中选择电子邮件就像“sadpanda”,并从“t2”接收这些用户的值。我应该为此使用内部联接吗?

4

2 回答 2

0
SELECT t2.*
FROM t2
JOIN t1 USING (cust_id)
WHERE t1.email = 'email3@sadpanda.com'

SQL 小提琴示例

于 2013-07-04T18:45:35.467 回答
0

你可能有两种方法 1. 你可以使用简单的连接查询。就像是

SELECT T2.*
FROM T1 JOIN T2 ON T.CUST_ID = T2.CUST_ID
WHERE T1.EMAIL LIKE '%sadpanda%'
  1. 或者你可以使用类似的子查询

    SELECT T2.* FROM T2 WHERE CUST_ID IN(SELECT CUST_ID FROM T1 WHERE T1.EMAIL LIKE '%sadpanda%')

我建议第一个。它会比第二个运行得更快。

于 2013-07-04T18:54:18.147 回答