0

我有 2 张桌子

      user                         user_address
user_id  name           user_address_id   city   user_id    address_type
   1     abc                 1             AAA      1         PRESENT
                             2             AAA      1         PERMANANT

我需要像这样的查询

select user model1 , user_address model2 where model1.user_id = distinct model2.user_id 

因为我知道两个地址是相同的,所以我只需要一次。我怎样才能得到一个地址。

提前致谢....

4

2 回答 2

0

尝试为 user_address 上的字段添加“分组依据”,如果它们仍然相同

select * from user_address inner join user as u on user_id = u.user_id group by city;
于 2013-09-12T12:36:05.427 回答
0

如果我理解正确你需要什么,你可以试试这个:

SELECT
    *
FROM (
    SELECT
        user_id,
        city ,
        address_type
    FROM
        user_address
    GROUP BY
        user_id

) as tmp
INNER JOIN user
    ON user.user_id = tmp.user_id
于 2013-09-12T12:39:23.057 回答