多列子查询不使用笛卡尔积

时间:2015-07-01 16:29:44

标签: mysql sql database subquery cartesian-product

SELECT 
   daf.id as affiliate_id,
   daf.name as affiliate_name,
   dal.name as allocation_name,
   dal.id as allocation_id,
   dal.allocation,dal.price
FROM 
     degreeamerica.affiliates daf,degreeamerica.allocations dal
JOIN 
     (select pap.lead_price,pap.live from paul.affiliates_price pap) pafp  
ON (dal.id=pafp.allocation_id and daf.id=pafp.affiliate_id) 
ORDER BY daf.id;

未知列pafp.allocation_id。我有这个专栏。但它不起作用。请帮忙。

1 个答案:

答案 0 :(得分:0)

似乎" allocation_id"未在子查询中选择列。 在子查询选定列中添加此列并检查。

SELECT 
   daf.id as affiliate_id,
   daf.name as affiliate_name,
   dal.name as allocation_name,
   dal.id as allocation_id,
   dal.allocation,dal.price
FROM 
     degreeamerica.affiliates daf,degreeamerica.allocations dal
JOIN 
     (select pap.lead_price,pap.live, allocation_id from paul.affiliates_price pap) pafp  
ON (dal.id=pafp.allocation_id and daf.id=pafp.affiliate_id) 
ORDER BY daf.id;