Created
September 7, 2016 20:29
-
-
Save sleroux/8653b0de73f44423b3941ff61cadbaa0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT DISTINCT historyID, url, title, guid, visitCount, visitDate, iconID, iconURL, iconType, iconDate, iconWidth | |
FROM ( | |
SELECT historyID, url, title, guid, visitCount, visitDate | |
FROM ( | |
SELECT * | |
FROM ( | |
SELECT history.id as historyId, bmkUri as url, bookmarksLocal.title as title, history.guid as guid, sum(1) as visitCount, max(visits.date) as visitDate, bookmarksLocal.local_modified as modified | |
FROM bookmarksLocal | |
LEFT JOIN history ON history.url = bookmarksLocal.bmkUri | |
LEFT JOIN visits ON history.id = visits.siteID | |
WHERE bookmarksLocal.title NOT NULL AND bookmarksLocal.title != '' AND bookmarksLocal.is_deleted = 0 AND bookmarksLocal.type = 1 | |
GROUP BY history.url | |
UNION | |
SELECT history.id as historyId, bmkUri as url, bookmarksMirror.title as title, history.guid as guid, sum(1) as visitCount, max(visits.date) as visitDate, bookmarksMirror.server_modified as modified | |
FROM bookmarksMirror | |
LEFT JOIN history ON history.url = bookmarksMirror.bmkUri | |
LEFT JOIN visits ON history.id = visits.siteID | |
WHERE bookmarksMirror.title NOT NULL AND bookmarksMirror.title != '' AND bookmarksMirror.is_deleted = 0 AND bookmarksMirror.is_overridden = 0 AND bookmarksMirror.type = 1 | |
GROUP BY history.url | |
) | |
WHERE visitCount <= 3 AND modified > 1473011862255728 | |
ORDER BY modified DESC | |
LIMIT 1 | |
) | |
UNION ALL | |
SELECT historyID, url, title, guid, visitCount, visitDate | |
FROM ( | |
SELECT history.id AS historyID, url, title, guid, sum(1) AS visitCount, max(visits.date) AS visitDate | |
FROM history | |
LEFT JOIN visits ON visits.siteID = history.id | |
WHERE title NOT NULL AND title != '' AND is_deleted = 0 | |
GROUP BY url | |
ORDER BY visitDate DESC | |
LIMIT 18 | |
) | |
WHERE visitCount <= 3 AND visitDate < 1473269262255725 | |
) | |
LEFT JOIN view_history_id_favicon ON view_history_id_favicon.id = historyID | |
GROUP BY url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment