2012-03-06 97 views
-1

我有兩個表,SQL命令,嵌套的SQL

  1. 計費( 「列」(bill_no,ITEM_NO))//法案沒有可以在數據庫中重複
  2. 項目( 「列」(ITEM_NO (PrimaryKey的),名稱,類型,價格)

我想知道的任何可能的查詢,以顯示我:

| bill_no | item_no | name | type | price |

我想說明* bill_no *和* * ITEM_NO項目全光照的計費表的n值* ITEM_NO * coloumn

謝謝。

+1

你有沒有嘗試去編寫查詢? – Vinnie 2012-03-06 17:18:48

+1

-1沒有嘗試 – 2012-03-06 17:23:07

回答

0

取決於你想與您的查詢做什麼,這裏有一些選擇:

select billing.bill_no 
, billing.item_no 
, item.name 
, item.type 
, item.price 
from billing, items 
where billing.item_no = items.item_no 

OR

select billing.bill_no 
, billing.item_no 
, item.name 
, item.type 
, item.price 
from billing 
join items on billing.item_no = items.item_no 
where billing.bill_no = 1234 
0

您可以使用一個簡單連接。

select billing.bill_no 
     ,billing.item_no 
     ,items.name 
     ,items.type 
     ,items.price 
from billing 
join items on items.item_no = billing.item_no 
0
Select b.bill_no 
     ,i.item_no 
     ,i.name 
     ,i.type 
     ,i.price 
from billing b 
    ,items i 
where i.item_no=b.item_no;