fix(sql): Remove alias

This commit is contained in:
Ahmad Ansori Palembani 2024-08-27 08:52:17 +07:00
parent 354ed7ce8a
commit a19b767aff
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6

View file

@ -65,9 +65,9 @@ LIMIT :limit OFFSET :offset;
getRecentsAll: -- AKA insanity getRecentsAll: -- AKA insanity
SELECT * FROM ( SELECT * FROM (
SELECT SELECT
M.*, mangas.*,
C.*, chapters.*,
H.* history.*
FROM ( FROM (
SELECT mangas.* SELECT mangas.*
FROM mangas FROM mangas
@ -83,11 +83,11 @@ FROM (
) )
GROUP BY _id GROUP BY _id
ORDER BY title ORDER BY title
) AS M ) AS mangas
JOIN chapters AS C JOIN chapters
ON M._id = C.manga_id ON mangas._id = chapters.manga_id
JOIN history AS H JOIN history
ON C._id = H.history_chapter_id ON chapters._id = history.history_chapter_id
JOIN ( JOIN (
SELECT SELECT
chapters.manga_id AS manga_id, chapters.manga_id AS manga_id,
@ -97,13 +97,13 @@ JOIN (
ON chapters._id = history.history_chapter_id ON chapters._id = history.history_chapter_id
GROUP BY chapters.manga_id GROUP BY chapters.manga_id
) AS max_last_read ) AS max_last_read
ON C.manga_id = max_last_read.manga_id ON chapters.manga_id = max_last_read.manga_id
AND max_last_read.history_chapter_id = H.history_chapter_id AND max_last_read.history_chapter_id = history.history_chapter_id
AND max_last_read.history_last_read > 0 AND max_last_read.history_last_read > 0
LEFT JOIN scanlators_view AS S LEFT JOIN scanlators_view AS S
ON C.manga_id = S.manga_id ON chapters.manga_id = S.manga_id
AND ifnull(C.scanlator, 'N/A') = ifnull(S.name, '/<INVALID>/') -- I assume if it's N/A it shouldn't be filtered AND ifnull(chapters.scanlator, 'N/A') = ifnull(S.name, '/<INVALID>/') -- I assume if it's N/A it shouldn't be filtered
WHERE lower(M.title) LIKE '%' || :search || '%' WHERE lower(title) LIKE '%' || :search || '%'
AND ( AND (
:apply_filter = 0 OR S.name IS NULL :apply_filter = 0 OR S.name IS NULL
) )
@ -113,11 +113,11 @@ UNION --
SELECT * FROM ( SELECT * FROM (
SELECT SELECT
M.*, mangas.*,
C.*, chapters.*,
NULL AS history_id, NULL AS history_id,
NULL AS history_chapter_id, NULL AS history_chapter_id,
C.date_fetch AS history_last_read, chapters.date_fetch AS history_last_read,
NULL AS history_time_read NULL AS history_time_read
FROM ( FROM (
SELECT mangas.* SELECT mangas.*
@ -134,28 +134,28 @@ FROM (
) )
GROUP BY _id GROUP BY _id
ORDER BY title ORDER BY title
) AS M ) AS mangas
JOIN chapters AS C JOIN chapters
ON M._id = C.manga_id ON mangas._id = chapters.manga_id
JOIN history AS H JOIN history
ON C._id = H.history_chapter_id ON chapters._id = history.history_chapter_id
JOIN ( JOIN (
SELECT SELECT
chapters.manga_id, manga_id,
chapters._id AS history_chapter_id, chapters._id AS history_chapter_id,
max(chapters.date_upload) max(date_upload)
FROM chapters JOIN mangas FROM chapters JOIN mangas
ON mangas._id = chapters.manga_id ON _id = manga_id
WHERE chapters.read = 0 WHERE read = 0
GROUP BY chapters.manga_id GROUP BY manga_id
) AS newest_chapter ) AS newest_chapter
LEFT JOIN scanlators_view AS S LEFT JOIN scanlators_view AS S
ON C.manga_id = S.manga_id ON chapters.manga_id = S.manga_id
AND ifnull(C.scanlator, 'N/A') = ifnull(S.name, '/<INVALID>/') -- I assume if it's N/A it shouldn't be filtered AND ifnull(chapters.scanlator, 'N/A') = ifnull(S.name, '/<INVALID>/') -- I assume if it's N/A it shouldn't be filtered
WHERE M.favorite = 1 WHERE favorite = 1
AND newest_chapter.history_chapter_id = H.history_chapter_id AND newest_chapter.history_chapter_id = history.history_chapter_id
AND C.date_fetch > M.date_added AND date_fetch > date_added
AND lower(M.title) LIKE '%' || :search || '%' AND lower(title) LIKE '%' || :search || '%'
AND ( AND (
:apply_filter = 0 OR S.name IS NULL :apply_filter = 0 OR S.name IS NULL
) )
@ -165,7 +165,7 @@ UNION --
SELECT * FROM ( SELECT * FROM (
SELECT SELECT
M.*, mangas.*,
NULL AS _id, NULL AS _id,
NULL AS manga_id, NULL AS manga_id,
NULL AS url, NULL AS url,
@ -181,11 +181,11 @@ SELECT
NULL AS source_order, NULL AS source_order,
NULL AS history_id, NULL AS history_id,
NULL AS history_chapter_id, NULL AS history_chapter_id,
M.date_added AS history_last_read, mangas.date_added AS history_last_read,
NULL AS history_time_read NULL AS history_time_read
FROM mangas AS M FROM mangas
WHERE M.favorite = 1 WHERE favorite = 1
AND lower(M.title) LIKE '%' || :search || '%' AND lower(title) LIKE '%' || :search || '%'
) )
ORDER BY history_last_read DESC ORDER BY history_last_read DESC
LIMIT :limit OFFSET :offset; LIMIT :limit OFFSET :offset;