Author |
Topic |
imliability
Starting Member
4 Posts |
Posted - 2012-01-15 : 14:07:24
|
select t.tutid,c.chapid from tutorial t join chapter c on (t.chapid=c.chapid) join book b on (c.isbn=b.isbn) join subject s on (b.subjcode=s.subjcode) where subjcode ='" & DropDownList1.Text & "'here is my database designand i got this error [DB2/NT] SQL0203N A reference to column "SUBJCODE" is ambiguous. SQLSTATE=42702 |
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2012-01-15 : 15:01:31
|
Two problems.- The column you have in the error message does not appear anywhere in the query you gave, nor does the query bear any resemblance at all to the tables in the design- You're using DB2, this is a Microsoft SQL Server forum. While we might be able to guess what's wrong if you post the actual query you ran, we might guess wrong because we're SQL Server people, not DB2 people--Gail ShawSQL Server MVP |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-15 : 22:55:50
|
i think my guess is you've SUBJCODE coming from more than one table (its in SUBJ,ENROLLED & BOOK in diagram) so if you're using it in joins make use you prefix it with tablename (or short aliases) else query engine wont be able to make out which table column you're trying to refer and will throw this error message------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
imliability
Starting Member
4 Posts |
Posted - 2012-01-16 : 00:21:24
|
quote: Originally posted by GilaMonster Two problems.- The column you have in the error message does not appear anywhere in the query you gave, nor does the query bear any resemblance at all to the tables in the design- You're using DB2, this is a Microsoft SQL Server forum. While we might be able to guess what's wrong if you post the actual query you ran, we might guess wrong because we're SQL Server people, not DB2 people--Gail ShawSQL Server MVP
sorry sir,i suppose to put my original query but i forgot to double check because i was so sleepy at that time...here is my original queryselect t.tutid,c.chapid from tutorial t join chapter c on (t.chapid=c.chapid) join book b on (c.isbn=b.isbn) join subject s on (b.subjcode=s.subjcode) where subjcode ='" & DropDownList1.Text & "' |
|
|
imliability
Starting Member
4 Posts |
Posted - 2012-01-16 : 00:21:43
|
quote: Originally posted by visakh16 i think my guess is you've SUBJCODE coming from more than one table (its in SUBJ,ENROLLED & BOOK in diagram) so if you're using it in joins make use you prefix it with tablename (or short aliases) else query engine wont be able to make out which table column you're trying to refer and will throw this error message------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
sorry sir,i suppose to put my original query but i forgot to double check because i was so sleepy at that time...here is my original queryselect t.tutid,c.chapid from tutorial t join chapter c on (t.chapid=c.chapid) join book b on (c.isbn=b.isbn) join subject s on (b.subjcode=s.subjcode) where subjcode ='" & DropDownList1.Text & "' |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-16 : 01:03:05
|
quote: Originally posted by imliability
quote: Originally posted by visakh16 i think my guess is you've SUBJCODE coming from more than one table (its in SUBJ,ENROLLED & BOOK in diagram) so if you're using it in joins make use you prefix it with tablename (or short aliases) else query engine wont be able to make out which table column you're trying to refer and will throw this error message------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
sorry sir,i suppose to put my original query but i forgot to double check because i was so sleepy at that time...here is my original queryselect t.tutid,c.chapid from tutorial t join chapter c on (t.chapid=c.chapid) join book b on (c.isbn=b.isbn) join subject s on (b.subjcode=s.subjcode) where subjcode ='" & DropDownList1.Text & "'
As i doubted you're missing an alias here. you should put correct table alias here to avoid ambiguity as subjcode is available in more than one table------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2012-01-16 : 03:52:12
|
select t.tutid,c.chapid from tutorial t join chapter c on (t.chapid=c.chapid) join book b on (c.isbn=b.isbn) join subject s on (b.subjcode=s.subjcode) where s.subjcode ='" & DropDownList1.Text & "'--Gail ShawSQL Server MVP |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-16 : 04:09:46
|
do you've some other query part following this. I notice you're missing a closing " after the last '------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
imliability
Starting Member
4 Posts |
Posted - 2012-01-16 : 10:00:55
|
quote: Originally posted by GilaMonster select t.tutid,c.chapid from tutorial t join chapter c on (t.chapid=c.chapid) join book b on (c.isbn=b.isbn) join subject s on (b.subjcode=s.subjcode) where s.subjcode ='" & DropDownList1.Text & "'--Gail ShawSQL Server MVP
this is work!!! |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2012-01-16 : 10:06:52
|
Do you understand why?--Gail ShawSQL Server MVP |
|
|
|