具有多个约束的查询

时间:2010-03-24 05:23:41

标签: sql

我有以下表格和字段:

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

我想过滤特定请求编号下选择的项目以及特定的请求者名称。我该怎么做呢?

2 个答案:

答案 0 :(得分: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 :(得分: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';