Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i'm trying to run this query,

 

select id from tblClientID where city = 'San Francisco' and city = 'San Jose'

 

 

if i have an id that can have several cities, shouldn't it display the id? my query returns nothing.

 

i.e., id 5 can have city san francisco and san jose and id 4 can only have san jose. what i want to do is if san francisco and san jose is chosen, that it will only return id 5. i don't want to use 'OR' because it will return both 4 and 5.

 

what am i doing wrong? if this isn't possible, how do i fix it?

 

i'm using MS Access.

Posted
From your statment. You have a city field in your table. This table conatins 1 city for each client, so what PlausiblyDamp is saying is that is only 1 city, not both. If you want a client to have many cities, then you have to separate out the city field into its own table then join on the client ID.
Posted

CLIENTS TABLE

ClientID int IDENTITY

CompanyName varchar(100)

 

CLIENT_CITIES TABLE

ClientID int

City varchar(100)

 

SELECT clients.companyname

FROM client_cities INNER JOIN

clients ON client_cities.clientid = clients.clientid INNER JOIN

client_cities client_cities_1 ON clients.clientid = client_cities_1.clientid

WHERE (client_cities.city = 'San Francisco') AND (client_cities_1.city = 'San Jose')

Posted
Will be easier if we know the structure of the table(s) involved, also if there is more than 1 table, the query by kahlua001 is ok too, but can be made in ANSI SQL to have more camptibility with other databases like SQL Server, Oracle, etc.
Fat kids are harder to kidnap
Posted

I'm using MS Access.

 

Here's an example of what i've been working on.

 

cityTable - Table name

cityID as Number (Primary Key)

cityName as Text

 

ClientTable

clientID as Number (Primary Key)

clientName as Text

 

ClientCityTable

clientID as number

ctyID as number

 

 

ClientCityTable can have several of the same clients listed but with different cityIDs.

 

i thought i kept this fairly simple, but perhaps i have it wrong.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...