jimmy
2007-03-08 04:30:03 UTC
/* INVMB table的 MB001欄位資料 MB006欄位資料 MB007欄位資料
SK1070-ACD90 2001
3001
SK1070-ACD90-3 2002
3002
INVMA table的 MA002欄位資料 MA003欄位資料
2001 AA
2002 BB
3001 CC
3002 DD
如果要將MB006、MB007 JOIN MA002並顯示結果為
MB001 MB006 MA003 MB007
MA003
SK1070-ACD90 2001 AA 3001
CC
SK1070-ACD90-3 2002 BB 3002
DD
請問如使用下SQL
以下是我寫的語法
SELECT
A.MB001,A.MB002,A.MB003,A.MB004,A.MB005,A.MB006,A.MB007,A.MB008,A.MB009,
B.MA003
FROM INVMB AS A LEFT JOIN INVMA AS B ON A.MB006 = B.MA002
WHERE A.MB001 LIKE 'SK%'
ORDER BY A.MB001
連結一個欄位沒問題,如果是連結兩個欄位會變成MA003欄位變成空值,語法如下
SELECT
A.MB001,A.MB002,A.MB003,A.MB004,A.MB005,A.MB006,A.MB007,A.MB008,A.MB009,
B.MA003
FROM INVMB AS A LEFT JOIN INVMA AS B ON A.MB006 = B.MA002 AND A.MB007 =
B.MA003
WHERE A.MB001 LIKE 'SK%'
ORDER BY A.MB001
問題出在哪邊,幫忙解答一下吧 ^.^
SK1070-ACD90 2001
3001
SK1070-ACD90-3 2002
3002
INVMA table的 MA002欄位資料 MA003欄位資料
2001 AA
2002 BB
3001 CC
3002 DD
如果要將MB006、MB007 JOIN MA002並顯示結果為
MB001 MB006 MA003 MB007
MA003
SK1070-ACD90 2001 AA 3001
CC
SK1070-ACD90-3 2002 BB 3002
DD
請問如使用下SQL
以下是我寫的語法
SELECT
A.MB001,A.MB002,A.MB003,A.MB004,A.MB005,A.MB006,A.MB007,A.MB008,A.MB009,
B.MA003
FROM INVMB AS A LEFT JOIN INVMA AS B ON A.MB006 = B.MA002
WHERE A.MB001 LIKE 'SK%'
ORDER BY A.MB001
連結一個欄位沒問題,如果是連結兩個欄位會變成MA003欄位變成空值,語法如下
SELECT
A.MB001,A.MB002,A.MB003,A.MB004,A.MB005,A.MB006,A.MB007,A.MB008,A.MB009,
B.MA003
FROM INVMB AS A LEFT JOIN INVMA AS B ON A.MB006 = B.MA002 AND A.MB007 =
B.MA003
WHERE A.MB001 LIKE 'SK%'
ORDER BY A.MB001
問題出在哪邊,幫忙解答一下吧 ^.^