このクエリに関する少しの助けを探しています。p.timer 列を使用して結果を降順で並べ替えようとしています。エラーはEvery derived table must have its own alias
、問題は clubs テーブルにエイリアスが必要であることだと思いますが、それが問題かどうかはわかりませんか?
これについて正しい方向に向けてくれてありがとう。
select *
from (
SELECT p.id,p.Display_Title,p.industry,p.location,p.timer,p.club_post,i.name,l.city,l.StateABBR, 1 as Rank
FROM `names` as p
INNER JOIN `clubs` as g ON p.club_post = '1,3,4,5,6'
INNER JOIN places as l ON l.id = p.location
INNER JOIN workforce as i ON i.id = p.industry
WHERE p.status = '1' AND p.status_1 = '1' AND p.category = '1'
ORDER BY p.timer DESC LIMIT 0,1)
UNION (
SELECT p.id,p.Display_Title,p.industry,p.location,p.timer,p.club_post,i.name,l.city,l.StateABBR, 2 as Rank
FROM `names` as p
INNER JOIN `clubs` as g ON p.club_post = '2'
INNER JOIN places as l ON l.id = p.location
INNER JOIN workforce as i ON i.id = p.industry
WHERE p.status = '1' AND p.status_1 = '1' AND p.category = '1'
ORDER BY p.timer DESC LIMIT 0,1)
UNION (
SELECT p.id,p.Display_Title,p.industry,p.location,p.timer,p.club_post,i.name,l.city,l.StateABBR, 3 as Rank
FROM `names` as p
INNER JOIN `clubs` as g ON p.club_post = '10'
INNER JOIN places as l ON l.id = p.location
INNER JOIN workforce as i ON i.id = p.industry
WHERE p.status = '1' AND p.status_1 = '1' AND p.category = '1,2'
ORDER BY p.timer DESC LIMIT 0,1)
UNION (SELECT p.id,p.Display_Title,p.industry,p.location,p.timer,p.club_post,i.name,l.city,l.StateABBR, 4 as Rank
FROM `names` as p
INNER JOIN `clubs` as g ON p.club_post = '11'
INNER JOIN places as l ON l.id = p.location
INNER JOIN workforce as i ON i.id = p.industry
WHERE p.status = '1' AND p.status_1 = '1' AND p.category = '1,2'
ORDER BY p.timer DESC LIMIT 0,1)
UNION (SELECT p.id,p.Display_Title,p.industry,p.location,p.timer,p.club_post,i.name,l.city,l.StateABBR, 5 as Rank
FROM `names` as p
INNER JOIN `clubs` as g ON p.club_post = '7'
INNER JOIN places as l ON l.id = p.location
INNER JOIN workforce as i ON i.id = p.industry
WHERE p.status = '1' AND p.status_1 = '1' AND p.category = '1'
ORDER BY p.timer DESC LIMIT 0,1)
UNION (SELECT p.id,p.Display_Title,p.industry,p.location,p.timer,p.club_post,i.name,l.city,l.StateABBR, 6 as Rank
FROM `names` as p INNER JOIN `clubs` as g ON p.club_post = '1,2,3,4,5,6'
INNER JOIN places as l ON l.id = p.location
INNER JOIN workforce as i ON i.id = p.industry
WHERE p.status = '1' AND p.status_1 = '1' AND p.category = '2'
ORDER BY p.timer DESC LIMIT 0,1)
ORDER BY rank,p.timer DESC LIMIT 0, 5