Please Help me,

I have 2 Table, A dan B.

Table A :
Sandar | jmlMuat
---------------------------
Mirah | 20
Berlian | 10

Table B :
Sandar | jmlBongkar
-------------------------------
Mirah | 30
Nilam | 15

I want to join that table to get result like this :
Sandar | jmlMuat | jmlBongkar
-------------------------------------------------
Mirah | 20 | 30
Nilam | Null | 15
Berlian | 10 | Null

I try Query :
SELECT A.Sandar, A.jmlBongkar, B.jmlMuat
FROM A full JOIN B
ON A.Sandar = B.Sandar

but the result is :

Sandar | jmlMuat | jmlBongkar
-------------------------------------------------
Mirah | 20 | 30
Null | Null | 15
Berlian | 10 | Null

why "Nilam" replace by "Null" ??

Whats wrong with my query?

Please correct my query so i get the result i want.

Thx.

Yusuf.

First off your example is incorrect. The "TableA" structure has jmlMuat in your table data, but in your query it has jmlBongkar. It looks like you swapped the tables ;)

Try this:

IF OBJECT_ID('tempdb..#TableA', 'U') IS NOT NULL DROP TABLE #TableA
IF OBJECT_ID('tempdb..#TableB', 'U') IS NOT NULL DROP TABLE #TableB

Create Table #TableA
(
  Sandar varchar(30),
  jmlMuat int
)
Insert Into #TableA (Sandar, jmlMuat) Values ('Mirah', 20)
Insert Into #TableA (Sandar, jmlMuat) Values ('Berlian', 10)

Create Table #TableB
(
  Sandar varchar(30),
  jmlBongkar int
)

Insert Into #TableB (Sandar, jmlBongkar) Values ('Mirah', 20)
Insert Into #TableB (Sandar, jmlBongkar) Values ('Nilam', 15)

Select *
From #TableA

Select *
From #TableB

SELECT COALESCE(A.Sandar, B.Sandar) As Sandar, A.jmlMuat, B.jmlBongkar
FROM #TableA as A full JOIN #TableB as B ON A.Sandar = B.Sandar

i try this and it success, thx Sknake....
your solution solve my problem....

I'm glad you got it working

Please mark this thread as solved if you have found an answer to your question and good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.