【发布时间】:2018-07-27 16:21:46
【问题描述】:
我有两个表 Table1 和 Table2 在表 1 列中,mobile 有多个 Mobile number 条目。 我想从table1中获取那些重复的手机号码的id,并在table2中搜索table1的id,其中clientId = table1.id。
我尝试了下面的SQL代码来获取重复手机号码的ID
SELECT id FROM table1 GROUP BY mobile HAVING COUNT(*) > 1
然后我尝试将值输入到 table1.id = table2.clientId 的新数组中
foreach ($table1data as $key) {
$items[] = \Yii::$app->db->createCommand("
SELECT clientId
FROM table2
WHERE clientId = :cid
")
->bindValue(':cid',$key['id'])
->queryAll();
}
【问题讨论】:
-
我觉得this的回答很有用