Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @SET @currcount = NULL, @currvalue = NULL;
- SELECT * from master_target_groups as mtgs
- RIGHT JOIN
- (
- SELECT *,
- @currcount := IF(@currvalue = master_target_group_id, @currcount+1, 1) AS rank,
- @currvalue := master_target_group_id AS unused
- from concept_targeting_groups ORDER BY master_target_group_id, created_at ASC
- ) as active_groups
- on mtgs.id = active_groups.master_target_group_id
- WHERE mtgs.company_id = 1300 AND active_groups.rank=1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement