What i'm trying to do is sub.blockid=id with the JOIN. I've renamed blockid as id in the subquery but the USING keyword is still attaching the column id instead of the renamed id column(blockid) from the subscribe table.
$subscribequery = "JOIN (SELECT id as subid, blockid as id from subscribe WHERE userid='1') AS sub
USING (id)";
This would be easy with ON but i have other JOIN subqueries with USING. I get the column is ambigious error if i try to use ON instead of USING along with the other subqueries.
Can you use both USING and ON in the same query? Can i rename the column as i have attempted above?
Here is the full query. The culprit is the second JOIN query.
SELECT * FROM products
JOIN (SELECT nid, sid, name AS max_name from products WHERE guideline='1' group by nid, sid) AS at1
USING (nid, sid)
JOIN (SELECT id as subid, blockid as id from subscribe WHERE userid='1') AS sub
USING (id)
WHERE id = subid AND name = max_name AND pending='0' AND deleted='0'
ORDER BY subid DESC, nid DESC;