tusharVaswani
tusharVaswani
Explore posts from servers
DTDrizzle Team
Created by tusharVaswani on 5/6/2024 in #help
Lateral joins
So not sure how I can use that with drizzle
3 replies
DTDrizzle Team
Created by tusharVaswani on 5/6/2024 in #help
Lateral joins
SELECT company_users.*, campaign_involved_in.campaign_id as campaign_involved_in
FROM company_users
LEFT JOIN (
SELECT company_user_campaign_mappings.campaign_id as campaign_id,
campaigns.status as campaign_status
FROM company_user_campaign_mappings
INNER JOIN campaigns
ON campaigns.id = company_user_campaign_mappings.campaign_id
WHERE company_user_campaign_mappings.company_user_id = company_users.id
ORDER BY company_users.created_at DESC
LIMIT 1
) as campaign_involved_in ON
campaign_involved_in.campaign_status NOT IN (1, 2, 8)
WHERE company_users.company_id = 1
AND company_users.is_archived = false
SELECT company_users.*, campaign_involved_in.campaign_id as campaign_involved_in
FROM company_users
LEFT JOIN (
SELECT company_user_campaign_mappings.campaign_id as campaign_id,
campaigns.status as campaign_status
FROM company_user_campaign_mappings
INNER JOIN campaigns
ON campaigns.id = company_user_campaign_mappings.campaign_id
WHERE company_user_campaign_mappings.company_user_id = company_users.id
ORDER BY company_users.created_at DESC
LIMIT 1
) as campaign_involved_in ON
campaign_involved_in.campaign_status NOT IN (1, 2, 8)
WHERE company_users.company_id = 1
AND company_users.is_archived = false
with this it gave same error. So after googling I found out that I had to use lateral joins.
3 replies