我有两张表,比如
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
因为我知道两个地址都是一样的,所以我只需要一次。我怎么只能得到一个地址。
提前致谢....
答案 0 :(得分:0)
尝试将“group by”放在user_address上的字段中,如果它们是相同的
select * from user_address inner join user as u on user_id = u.user_id group by city;
答案 1 :(得分: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