Skip to content

Instantly share code, notes, and snippets.

@Danack
Created October 29, 2014 17:03
Show Gist options
  • Save Danack/1fde50e853fd6876f43d to your computer and use it in GitHub Desktop.
Save Danack/1fde50e853fd6876f43d to your computer and use it in GitHub Desktop.
CREATE TEMPORARY TABLE mediaSelected (
mediaId int,
itemId int
);
CREATE TEMPORARY TABLE mediaRejected (
mediaID int,
itemID int
);
insert into mediaSelected
SELECT
`mediaId`,
`itemId`
FROM
`cmcCMS`.`tagItems`
WHERE
`tagId` IN (118,4)
GROUP BY itemId
HAVING (COUNT(tagId) = 2);
insert into mediaRejected
SELECT
`mediaId`,
`itemId`
FROM
`cmcCMS`.`tagItems`
WHERE
`tagId` IN (122,452,612);
SELECT
`media`.`id`
FROM
`media`
left join mediaSelected
on mediaSelected.mediaId = media.id
left outer join mediaRejected
on mediaRejected.mediaId = media.id
ORDER BY
`media`.`postedOn` DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment