2016-04-15 139 views
0

當單個表如何獲得它們的範圍內的記錄,我用這個查詢得到的範圍內記錄:連接兩個表

SELECT customerId,firstName,lastName FROM customer WHERE customerId BETWEEN min AND max; 

但連接兩個表後,怎麼能我得到範圍內的記錄。 在這裏,我使用的外鍵下面,

customer.productId = productDetails.productId 

我的查詢:

SELECT customer.custId, customer.productId,GROUP_CONCAT(productDetails.productName) as productName, GROUP_CONCAT(productDetails.productPrice) as productPrice FROM customer, productDetails WHERE customer.productId = productDetails.productId GROUP BY productDetails.productId 
+0

你是什麼結果? –

+0

我的結果:custId | productId |產品名稱| productPrice | 1000 | 371000 |看,預訂| 700,500 | – dev777

回答

1
from what I understand you just need to add an "AND" condition to the query 


WHERE customer.productId = productDetails.productId 
AND customer.custId BETWEEN min and max; 
GROUP BY productDetails.productId 
+0

非常感謝,它爲我工作 – dev777