Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have two tables namely PESANMASUK anda KONTAK. in PESANMASUK i have 5 fileds : IDMASUK, TANGGALMASUK, JAM, NOMERHP, ISIPESAN . and KONTAK i have 3 fileds : IDKONTAK, NAMA, NOHP.

PESANMASUK table :
CSS
IDMASUK	TANGGALMASUK	JAM	NOMERHP		ISIPESAN
1	09/08/2015	09:00	+62847776	try sms
2	08/08/2015	10:00	+62856790	plase come in
3	08/08/2015	06:00	+6283444	you and me


KONTAK table :
CSS
IDKONTAK	NAMA		NOHP
1		RIAN		+62847776
2		ALFIAN		+62856790


and this result is i want :
CSS
IDMASUK	TANGGALMASUK	JAM	NOMERHP		NAMA		ISIPESAN
1	09/08/2015	09:00	+62847776	RIAN	try sms
2	08/08/2015	10:00	+62856790	ALFIAN		plase come in
3	08/08/2015	06:00	+6283444			you and me


this is my oracle query :
SQL
SELECT IDMASUK, TANGGALMASUK, JAM, NOMERHP, ISIPESAN, 
(SELECT NAMA FROM KONTAK WHERE NOHP IN (SELECT NOMERHP FROM PESANMASUK)) AS NAMA 
FROM PESANMASUK

I got error like this :
SQL
ORA-01427: single-row subquery returns more than one row

I wanna matching between NOMERHP in PESANMASUK and NAMA in KONTAK and return all rows.
how can I solve this??
Posted
Updated 1-Mar-21 9:52am
v2

Basically, you need to join data[^]:
SQL
SELECT Table1.Field1, Table2.Field1
FROM Table1 INNER JOIN Table2 ON Table1.PK = Table2.FK

Where
PK = Primary Key[^],
FK = Foreign Key[^].

For further information, please see: Visual Representation of SQL Joins[^]
 
Share this answer
 
Comments
aminvincent 10-Aug-15 20:18pm    
in those table no relation,...finally i used this query and it worked :
SELECT IDMASUK, TANGGALMASUK, JAM, NOMERHP, ISIPESAN, NAMA
FROM PESANMASUK
LEFT JOIN KONTAK
ON KONTAK.NOHP = PESANMASUK.NOMERHP
ORDER BY TANGGALMASUK DESC, JAM DESC
Maciej Los 11-Aug-15 2:15am    
So, you did what i suggested. Please, accept my answer as a solution (green button) - formally to remove question drom unanswered list.
SQL
SELECT IDMASUK, TANGGALMASUK, JAM, NOMERHP, ISIPESAN,
(SELECT NAMA FROM KONTAK WHERE NOHP IN (SELECT NOMERHP FROM PESANMASUK) and ROWNUM <= 1) AS NAMA
FROM PESANMASUK


please try this
 
Share this answer
 
Comments
aminvincent 10-Aug-15 2:25am    
Praveen : i have tried your query above but result NAMA replace just one name,...any solution else?
[no name] 10-Aug-15 4:23am    
SELECT IDMASUK, TANGGALMASUK, JAM, NOMERHP, ISIPESAN,
(SELECT listagg(NAMA,',') within group (order by null) FROM KONTAK WHERE NOHP IN (SELECT NOMERHP FROM PESANMASUK)) AS NAMA
FROM PESANMASUK

This will return you more records in comma seperated
aminvincent 10-Aug-15 20:17pm    
praveen : thanks for your help,.but now i have fixed it and my query work...
this my query : SELECT IDMASUK, TANGGALMASUK, JAM, NOMERHP, ISIPESAN, NAMA
FROM PESANMASUK
LEFT JOIN KONTAK
ON KONTAK.NOHP = PESANMASUK.NOMERHP
ORDER BY TANGGALMASUK DESC, JAM DESC

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900