SELECT distinct referrals.listing_id,submissions.listing_name
FROM submissions
INNER JOIN referrals ON referrals.listing_id=submissions.listing_id;
如果我这样做
SELECT distinct referrals.listing_id,submissions.listing_name,referrals.timestamp
FROM submissions
INNER JOIN referrals ON referrals.listing_id=submissions.listing_id;
它为我提供了许多其他没有distinct listing_id
我希望distinct listing_id
有他们的时间戳(这些时间戳不同,但是根据distinct listing_id
)
答案 0 :(得分:3)
如果您希望每个列表包含一行,请使用聚合。例如:
GROUP BY
Treatment.Treatment_Date,
Salutation.Value,
Customer.Firstname,
Customer.Lastname,
Address.Value,
Postal.Postal,
Postal.City,
Patient.Name,
TreatmentType.Type,
Treatment.Price,
Tax.Value
SELECT r.listing_id, s.listing_name, max(r.timestamp) as most_recent_timestamp
FROM submissions s INNER JOIN
referrals r
ON r.listing_id = s.listing_id
GROUP BY r.listing_id, s.listing_name;
适用于SELECT DISTINCT
。