Linking queries error code 1052 -
i getting error code 1052 column firestationhome in field list ambiguous when trying equijoin 2 tables in query
this code using below:
select firemanid, firemanhomestation,stationphone fire_report f, fire_station fs f.firemanhomestation = fs.firemanhomestation , stationphone ='703';
from reading through forums understanding need link first relation linking key. firemanhomestation linking key need run following directions.
display firemanid, firemanhomestation, , phone number of station firefighters numbers begin '703'.
using boyce codd method have normalized following
fire_report(fireid,alarms,address,firemanid,firemanname,firemanphone,firemanhomestation,stationaddress,stationphone,truckid,licenseplate)
the rules:
each fire can have several firefighters assigned it
each fire can have several fire trucks assigned it
each firefighter can assigned several fires
each fire truck , assigned several fires
each firefighter has single home station
each station unique
each station has single phone number
primary keys
fireid, firemanid, firemanhomestation,truckid fireid -> alarms, address firemanid -> firemanname, firemanphone, firemanhomestation firemanhomestation -> stationaddress, stationphone truckid -> licenseplate
fire_report(fireid, firemanid, firemanhomestation, truckid)
fire(fireid, alarms, address)
fireman_id(firemanid, firemanname, firemanphone)
fire_station(firemanhomestation, stationaddress, stationphone)
truck(truckid, licenseplate)
referential integrity constraints
fireid in fire_report must exist in fireid in fire
firemanid in fire_report must exist in firemanid in fireman_id
firemanhomestation in fire_report must exist in firemanhomestation in fire_station
truckid in fire_report must exist in truckid in truck
create schema project_george;<br> use project_george;<br> create table fire (<br> fireid int(3) not null,<br> alarms int(1) not null,<br> address varchar(25) not null,<br> constraint fire_pk primary key(fireid),<br> constraint fire_fr_fk foreign key(fireid)<br> references fire_report(fireid)<br> on update cascade<br> );<br> create table fireman_id (<br> firemanid int(3) not null,<br> firemanname varchar(25) not null,<br> firemanphone char(10) not null unique,<br> constraint fi_pk primary key(firemanid),<br> constraint fi_fr_fk foreign key(firemanid)<br> references fire_report(firemanid)<br> on update cascade<br> );<br> create table fire_station (<br> firemanhomestation varchar(25) not null unique,<br> stationaddress varchar(25) not null,<br> stationphone char(10) not null,<br> constraint fs_pk primary key(firemanhomestation),<br> constraint fs_fr_fk foreign key(firemanhomestation)<br> references fire_report(firemanhomestation)<br> on update cascade<br> );<br> create table truck (<br> truckid int(3) not null,<br> licenseplate char(5) not null unique,<br> constraint truck_pk primary key(truckid),<br> constraint truck_rc_fk foreign key(truckid)<br> references fire_report(truckid)<br> on update cascade<br> );<br> create table fire_report (<br> fireid int(3) not null,<br> firemanid int(3) not null,<br> firemanhomestation varchar(25) not null,<br> truckid int(3) not null,<br> constraint fr_pk primary key(fireid,firemanid,firemanhomestation,truckid),<br> constraint fr_f_fk foreign key (fireid)<br> references fire(fireid) <br> on update cascade,<br> constraint fr_fid_fk foreign key(firemanid)<br> references fireman_id(firemanid)<br> on update cascade,<br> constraint fr_fs_fk foreign key(firemanhomestation)<br> references fire_station(firemanhomestation)<br> on update cascade,<br> constraint fr_truck_fk foreign key(truckid)<br> references truck(truckid)<br> on update cascade<br> );<br><br> insert fire values(100, 1, '4025 medford dr, annandale va 22003');<br> insert fire values(101, 2, '7031 little river turnpike suite 5a annandale, va 22003-5958');<br> insert fire values(102, 3, '7001 little river turnpike, annandale, va 22003 ');<br> insert fire values(103, 4, '8333 little river turnpike annandale, va 22003');<br> insert fire values(104, 5, '1600 pennsylvania ave nw washington, dc 20500');<br><br> insert fireman_id values(100, 'guliza ormuzokova', '703-221-9918');<br> insert fireman_id values(101, 'lex steele', '703-911-4450');<br> insert fireman_id(firemanid,firemanname,firemanphone) values(102, 'george putnam', '703-222-9918');<br> insert fireman_id values(103, 'steven drasner', '571-939-1234');<br> insert fireman_id values(104, 'judy miller', '571-999-1234');<br> insert fireman_id values(105, 'lily thai', '703-911-4451');<br><br> insert fire_station values('station 29', '571 broad st fairfax va 22030', '703-200-9918');<br> insert fire_station values('station 229', '8914 little river turnpike, fairfax, va 22031 ', '703-900-4450');<br> insert fire_station values('station 429', '3988 university dr, fairfax, va 22030 ', '571-900-1234');<br><br> insert truck values(1, 'burn29');<br> insert truck values(2, 'burn19');<br> insert truck values(3, 'burn09');<br><br> /************i can't figure on out!!!*** *****/<br> select firemanid, firemanhomestation,stationphone<br> fire_report f, fire_station fs<br> f.firemanhomestation = fs.firemanhomestation<br> , stationphone ='703';<br>
firemanhomestation existing in both table don't specify table want result, ambiguous.
select firemanid, fs.firemanhomestation,stationphone fire_report f, fire_station fs f.firemanhomestation = fs.firemanhomestation , stationphone ='703';
should work
Comments
Post a Comment