LJackson
08-12-2011, 01:21 PM
i have this query
SELECT * , count( * ) AS howmany
FROM tbl_popularity AS pop
LEFT JOIN (
tbl_dvds AS dvd
) ON pop.prodID = dvd.filmID
WHERE dvd.filmBinding = '$cSect' && pop.prodID <>0 && pop.dateStamp > DATE_SUB( curdate( ) , INTERVAL 30
DAY )
GROUP BY `prodID`
ORDER BY howmany DESC
LIMIT 0 , 6
and on the join i need to select certain fields like i have in this query
SELECT filmID as id, filmName as name, filmThumbIMG as img, filmThumbHeight as height, filmThumbWidth as width, filmRRP as rrp, filmBinding as binding
FROM tbl_dvds
i tried this
SELECT * , count( * ) AS howmany
FROM tbl_popularity AS pop
LEFT JOIN (
SELECT filmID as id, filmName as name, filmThumbIMG as img, filmThumbHeight as height, filmThumbWidth as width, filmRRP as rrp, filmBinding as binding FROM tbl_dvds AS dvd
) ON pop.prodID = dvd.filmID
WHERE dvd.filmBinding = 'DVD' && pop.prodID <>0 && pop.dateStamp > DATE_SUB( curdate( ) , INTERVAL 30
DAY )
GROUP BY `prodID`
ORDER BY howmany DESC
LIMIT 0 , 6
but it says Every derived table must have its own alias?
can i do that using the left join or do i need to use union? and will union enable me to product the same outputs as my first query?
thanks
Luke
SELECT * , count( * ) AS howmany
FROM tbl_popularity AS pop
LEFT JOIN (
tbl_dvds AS dvd
) ON pop.prodID = dvd.filmID
WHERE dvd.filmBinding = '$cSect' && pop.prodID <>0 && pop.dateStamp > DATE_SUB( curdate( ) , INTERVAL 30
DAY )
GROUP BY `prodID`
ORDER BY howmany DESC
LIMIT 0 , 6
and on the join i need to select certain fields like i have in this query
SELECT filmID as id, filmName as name, filmThumbIMG as img, filmThumbHeight as height, filmThumbWidth as width, filmRRP as rrp, filmBinding as binding
FROM tbl_dvds
i tried this
SELECT * , count( * ) AS howmany
FROM tbl_popularity AS pop
LEFT JOIN (
SELECT filmID as id, filmName as name, filmThumbIMG as img, filmThumbHeight as height, filmThumbWidth as width, filmRRP as rrp, filmBinding as binding FROM tbl_dvds AS dvd
) ON pop.prodID = dvd.filmID
WHERE dvd.filmBinding = 'DVD' && pop.prodID <>0 && pop.dateStamp > DATE_SUB( curdate( ) , INTERVAL 30
DAY )
GROUP BY `prodID`
ORDER BY howmany DESC
LIMIT 0 , 6
but it says Every derived table must have its own alias?
can i do that using the left join or do i need to use union? and will union enable me to product the same outputs as my first query?
thanks
Luke