2010-03-24 88 views
0

我有以下的表和字段:查詢與多約束

 
+------------------+ +-------------------+ +---------------+ 
| Request   | | RequestItem  | | Item   | 
+------------------+ +-------------------+ +---------------+ 
| + Requester_Name | | + Request_No  | | + Item  | 
+------------------+ +-------------------+ +---------------+ 
| + Request_No  | | + Item   | 
+------------------+ +-------------------+ 

我想過濾其下一個特定的請求數選擇,與特定的請求者名一起的項目。我該如何去做這件事?

+1

旗幟冒犯 - 對我的眼睛冒犯。 – 2010-03-24 05:25:17

+0

@Coronatus:請給ANITHA一些你不喜歡它的原因。 – Oddthinking 2010-03-24 05:43:21

+0

@Oddthinking:看看修訂日誌 – 2010-03-24 05:46:28

回答

1

在SQL中?當然,我沒有測試過這一點,但什麼:

SELECT items 
FROM item INNER JOIN requestitem ON item.items = requestitem.item 
WHERE requestitem.request_no = Whatever_Request_Number_You_Want 

或者怎麼樣:

SELECT items 
FROM item INNER JOIN requestitem ON item.items = requestitem.item 
INNER JOIN request ON requestitem.request_no = request.request_no 
WHERE request.requester_name = 'Whatever_Name_You_Want' 
+1

注意:字段名稱(和表名稱)是「項目」,而不是「項目」在原來的問題。 – Oddthinking 2010-03-24 05:42:31

+2

是的,但是來自原始問題的**第一修訂版本:「在項目表下我有一個被稱爲項目的項目」; http://stackoverflow.com/revisions/161f51f2-1404-4495-9865-8daa49a7ce64/view-source – 2010-03-24 05:52:47

1

製作有關的數據是什麼樣子,但這裏的一個嘗試一些假設:

SELECT item 
FROM requestitem 
    JOIN item ON requestitem.item = item.item 
    JOIN request ON requestitem.request_no = request.request_no 
WHERE 
    request.request_no = 8642 
    AND request.requester_name = 'Specific J. Requester';