我正在使用以下查詢來獲取客戶詳細信息。但它不起作用,請幫助我。我是SQL新手。在主查詢中獲取子查詢值
select cu.fld_cust_id,ord.* from test1 where fld_order_id ord in (select * from tbl_customer cu where cu.fld_status=1);
我正在使用以下查詢來獲取客戶詳細信息。但它不起作用,請幫助我。我是SQL新手。在主查詢中獲取子查詢值
select cu.fld_cust_id,ord.* from test1 where fld_order_id ord in (select * from tbl_customer cu where cu.fld_status=1);
您不能選擇從WHERE
子句中使用子查詢列,becaused他們沒有加入到這個查詢。你只是使用這個子查詢返回的值範圍
你的子查詢應該只返回一列。
你應該嘗試這樣的事情。
SELECT cu.fld_cust_id,ORD * FROM test1的 JOIN tbl_customer銅ON cu.fld_status = 1 AND fld_order_id = cu.fld_cust_id
fld_order_id = cu.fld_cust_id沒有意義,ord也沒有意義。* –
你說得對,但我們實際上並不知道這些表的樣子。 –
在查詢中,你還需要知道,你可以只能看到當前範圍中的字段。因此,在主查詢中,您只能使用FROM TEST1,因此您只能看到該表中的字段。 ord。*和cu的使用會給出錯誤。如果您需要該表中的其他字段,請使用JOIN。 TEST1表應該包含一個鏈接到TBL_CUSTOMER的外鍵,如果不是,則需要使用其他表的路徑或重新設計數據庫。如果你有外鍵,這就是你身邊的IN操作符用什麼:
select fld_cust_id from test1 where fld_cust_id in (select id from tbl_customer cu where cu.fld_status=1);
不知道什麼在你的tbl_customer,但好像你是匹配fld_order_id爲*。您應該匹配客戶表中的order_id。
select cu.fld_cust_id,ord.*
from test1
where fld_order_id ord in (
select *ORDERID* from tbl_customer cu where cu.fld_status=1
);
你能明確指定你想要的嗎? –