Hi there sneakyimp,
I took your advice and continued working with your last suggested query and think I figured out what I had done wrong. It was an issue I created in modifying the query for when someone didn't have any negatively scored categories. I tested all three queries. The singlejoin query was bringing in duplicate records. The sub query looked like it was doing ok until I went to the oldest record. For some reason it was including a link showing completely null values.
So, your query, modified as I needed. Let me know if you see anything amiss.
If all they have is favorites, it will look like this:
SELECT DISTINCT u.* FROM
linkcats lc
LEFT JOIN shortenified_urls u ON (u.id=lc.link_id AND u.is_social='1' AND u.active='1')
WHERE
lc.cat_id IN (17,1,35,33,50)
ORDER BY u.date_added DESC
and when they have some unfavorites, it looks like this:
SELECT DISTINCT u.* FROM
linkcats lc
LEFT JOIN shortenified_urls u ON (u.id=lc.link_id AND u.is_social='1' AND u.active='1')
LEFT JOIN linkcats lc2 ON (u.id=lc2.link_id AND lc2.cat_id IN (28))
WHERE
lc.cat_id IN (17,1,35,33,50)
AND lc.cat_id NOT IN (28)
AND lc2.link_id IS NULL
ORDER BY u.date_added DESC
These are for viewing only unread content. There's two ways that the system determines this. They can mark all as read, creating a timestamp. Anything older than the timestamp is hidden. The second method is in the linkviews table. In my other queries it's a left join, so I'm trying to attach a third to your code. Here's what I've done:
With no unfaves and viewing unread only:
SELECT DISTINCT u.* FROM
linkcats lc
LEFT JOIN shortenified_urls u ON (u.id=lc.link_id AND u.is_social='1' AND u.active='1')
LEFT JOIN linkviews lv
ON lv.lid = u.id
AND lv.uid = 2
WHERE
lc.cat_id IN (17,1,35,33,50)
AND u.date_added > 0
AND lv.id IS NULL
ORDER BY u.date_added DESC
With unfaves and unread only:
SELECT DISTINCT u.* FROM
linkcats lc
LEFT JOIN shortenified_urls u ON (u.id=lc.link_id AND u.is_social='1' AND u.active='1')
LEFT JOIN linkcats lc2 ON (u.id=lc2.link_id AND lc2.cat_id IN (17))
LEFT JOIN linkviews lv
ON lv.lid = u.id
AND lv.uid = 2
WHERE
lc.cat_id IN (1,35,33,50,2)
AND lc.cat_id NOT IN (17)
AND lc2.link_id IS NULL
AND u.date_added > 1424630215
AND lv.id IS NULL
ORDER BY u.date_added DESC
I've tested as much as I am able and they all seem to be working. Unless you have a suggestion on handling my additions better, it looks like these may be what I run with.
Thanks so much for all your help!