running32
asked on
Problem with select statement
I have a select statement and each time I try to select I get differenct errors.
select org.name, loc.address1, loc.address2, loc.city, loc.state, loc.zip,phones.phone from locations as loc, organizations as org , phones
inner join organizationlocations as orgloc on org.organizationid = orgloc.organizationid
inner join locations as loc1 on orgloc.locationsid = loc1.locationid
The one I am getting at the moment is
Line 1
The column prefix 'org' does not match with a table name or alias name used in the query.
Thanks
select org.name, loc.address1, loc.address2, loc.city, loc.state, loc.zip,phones.phone from locations as loc, organizations as org , phones
inner join organizationlocations as orgloc on org.organizationid = orgloc.organizationid
inner join locations as loc1 on orgloc.locationsid = loc1.locationid
The one I am getting at the moment is
Line 1
The column prefix 'org' does not match with a table name or alias name used in the query.
Thanks
woah, you are joining locations back to itself? why? your query should be:
select org.name, loc.address1, loc.address2, loc.city, loc.state, loc.zip,phones.phone from locations loc, organizations org , phones
inner join organizationlocations orgloc on org.organizationid = orgloc.organizationid
and orgloc.locationsid = loc1.locationid
select org.name, loc.address1, loc.address2, loc.city, loc.state, loc.zip,phones.phone from locations loc, organizations org , phones
inner join organizationlocations orgloc on org.organizationid = orgloc.organizationid
and orgloc.locationsid = loc1.locationid
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I guess my query does not work at all.
What I need is the name, address from the tables organization and locations.
These tables are linked by a locationid. organization table has organizationid and organizationlocations table has organizationid and locationid. Then locations table has locations id. I need to join up the 3 tables so that I can pull the information.
Thanks for your help
What I need is the name, address from the tables organization and locations.
These tables are linked by a locationid. organization table has organizationid and organizationlocations table has organizationid and locationid. Then locations table has locations id. I need to join up the 3 tables so that I can pull the information.
Thanks for your help
select
org.name
, loc.address1
, loc.address2
, loc.city
, loc.state
, loc.zip
, phones.phone
from
locations loc
inner join
organizationlocations orgloc on
loc.locationid = orgloc.locationid
inner join
organizationlocations orgloc on
org.organizationid = orgloc.organizationid
inner join
phones on
loc.locationid = phones.locationid
org.name
, loc.address1
, loc.address2
, loc.city
, loc.state
, loc.zip
, phones.phone
from
locations loc
inner join
organizationlocations orgloc on
loc.locationid = orgloc.locationid
inner join
organizationlocations orgloc on
org.organizationid = orgloc.organizationid
inner join
phones on
loc.locationid = phones.locationid
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks guys for answering back so quickly I really appricate it.
inner join organizationlocations orgloc on org.organizationid = orgloc.organizationid
inner join locations loc1 on orgloc.locationsid = loc1.locationid