Jump to content

DISTINCT for two fields in JOIN


sKunKbad

Recommended Posts

I've got a query that may produce multiple results because of multiple tenants records, but I need to have only one result per unit:

 

SELECT 
DISTINCT u.`unit-id`, 
u.`street-address`, 
u.`property-id-fk`, 
u.`suite-no`, 
t.`tenant-id`
FROM unit_table u
LEFT JOIN tenant_table t
ON u.`unit-id` = t.`unit-id-fk`
WHERE u.`status` = 'Inactive' 
AND u.`owner-id-fk` = ?

 

This doesn't work unless I dont select tenant-id, but I need a tenant-id. If I put DISTINCT before t.`tenant-id` it produces an error. How can I have the query only return a single row for each unit AND tenant?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.