View Full Version : SQL join function
mattroxxx
28-08-03, 02:32 PM
:salam:
ni ada satu kemusykilan...
select a,b from person where ic_no=?
union
select c,d from org where reg_no=?
let's say ada pertambahan...
select a,b,e,f from person where ic_no=?
union
select c,d from org where reg_no=?
akan kluar error:
"query block has incorrect number of result columns"
means that query tu tak balance...
Soalannya
camna nak 'balance'kan query 1st ngan 2nd? query 2nd cuma ada attribute c dan d je..
trima kasih.
neo^ternity
29-08-03, 02:15 AM
aku rasa ko masuk command jer.. kat database ko takde collum tuk e,f.. .. tul ke.. aku x berapa paham apa ko tulis nie.. main agak-2 jerk
mattroxxx
29-08-03, 03:46 PM
katakan table person ada attribut id, name, ic_no, passport_no, nationality
katakan table org ada attribut id,name, reg_no
pastu sql command utk join
select id,name,passport_no,nationality from person where ic_no=?
union
select id,name from org where reg_no=?
bila aku buat camni....dia kuar error:
"query block has incorrect number of result columns"
means that join query tu tak balance...sbb kat table org just ada 2 att/column je...
Soalannya
camna nak 'balance'kan query 1st ngan 2nd?
sbb aku find out that kalo 1st query tu aku letak 2, 2nd query aku letak 2, dia tade error...paham??
tolong la ye....thank...
Q: I tried to use UNION but I got
ORA-01789: query block has incorrect number of result columns.
I have only some of the columns in the other table.
A: You have to define the missing columns. Note the number
of spaces between the single quotes.
- character:
select ' ', ename from foo -- One space between the single quotes
union
select charcol, ename from table;
- number:
select 0, ename from foo
union
select numericcol, ename from table
- date:
select to_date(''), ename from foo --No space between the single quotes
union
select datecol, ename from table
so ko punyer statement maybe lebih kurang camni
select id,name,passport_no,nationality from person where ic_no=?
union
select id,name,0,' ' from org where reg_no=?
dgn anggapan pasport_no =number, natinality = char
http://www.fors.com/orasupp/d2k/plus/2194_1.HTM
mattroxxx
30-08-03, 09:22 PM
erm....aku dah dapat jawapannya..
aku buat dummy je..
ni yg aku buat..
select id,name,passport_no,nationality from person where ic_no=?
union
select id,name,name,name from org where reg_no=?
nnt aku try buat cara ko tu...tq. :::
kambinggila
15-10-03, 04:54 PM
Kiriman asal oleh mattroxxx
:salam:
ni ada satu kemusykilan...
select a,b from person where ic_no=?
union
select c,d from org where reg_no=?
let's say ada pertambahan...
select a,b,e,f from person where ic_no=?
union
select c,d from org where reg_no=?
akan kluar error:
"query block has incorrect number of result columns"
means that query tu tak balance...
Soalannya
camna nak 'balance'kan query 1st ngan 2nd? query 2nd cuma ada attribute c dan d je..
trima kasih.
jangan guna union select
guna join jer.. tapi ada apa apa field yang buleh relatekan dedua table tak?
vBulletin® v3.7.1, Copyright ©2000-2009, Jelsoft Enterprises Ltd.