By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,483 Members | 1,544 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,483 IT Pros & Developers. It's quick & easy.

SQL - join hassle?

P: n/a
Hi all,

Sorry to hassle you with this query, I'm sure the answer is a simple
one, but it remains elusive - to me anyway.

What I am trying to do is get a query to work. I have a table of people
(with ID's) and a table of languages (with People IDs and Language IDs).
Now one person may speak many languages. I have put in the relationship.
What I want is to be able to say pull out all the people wjo speak these
3 languages.

The query I manage to make is this

SELECT DISTINCT People.ID_Person
FROM People INNER JOIN People_LanguageSkills ON People.ID_Person =
People_LanguageSkills.ID_Person
WHERE (((People_LanguageSkills.ID_Language)=[Forms]![Form1]![Combo22]));

The moment I add
AND (((People_LanguageSkills.ID_Language)=[Forms]![Form1]![Combo32]))

It stops working. It now says that no-one speaks English (ID 1) and
French (ID 3). I have checked to make sure that there are people in the
People_Languageskills table who have both languages:)

I have tried to select from only the People_Languageskills table and
from the joined tables as above.

What am I doing wrong????

Thanks in advance

Jenni

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Jenni wrote:
Hi all,

Sorry to hassle you with this query, I'm sure the answer is a simple
one, but it remains elusive - to me anyway.

What I am trying to do is get a query to work. I have a table of people
(with ID's) and a table of languages (with People IDs and Language IDs).
Now one person may speak many languages. I have put in the relationship.
What I want is to be able to say pull out all the people wjo speak these
3 languages.

The query I manage to make is this

SELECT DISTINCT People.ID_Person
FROM People INNER JOIN People_LanguageSkills ON People.ID_Person =
People_LanguageSkills.ID_Person
WHERE (((People_LanguageSkills.ID_Language)=[Forms]![Form1]![Combo22]));

The moment I add
AND (((People_LanguageSkills.ID_Language)=[Forms]![Form1]![Combo32]))

It stops working. It now says that no-one speaks English (ID 1) and
French (ID 3). I have checked to make sure that there are people in the
People_Languageskills table who have both languages:)

I have tried to select from only the People_Languageskills table and
from the joined tables as above.

What am I doing wrong????


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
It should be OR instead of AND:

WHERE People_LanguageSkills.ID_Language=[Forms]![Form1]![Combo22]
OR People_LanguageSkills.ID_Language=[Forms]![Form1]![Combo32]

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQHwsLoechKqOuFEgEQKqNgCgxSXpTCSr8ioRfZfZpSADM2 p7OpwAn22o
FQ0goSQ+fJuIEYoweafEuK0m
=8+DL
-----END PGP SIGNATURE-----

Nov 12 '05 #2

P: n/a
Jenni,

You need to add People_LanguageSkills to the query once for every language
you want to compare. Your query will look something like this (I haven't
tested it):

SELECT DISTINCT People.ID_Person
FROM (People INNER JOIN People_LanguageSkills AS Language1
ON People.ID_Person = Language1.ID_Person)
INNER JOIN People_LanguageSkills AS Language2
ON People.ID_Person = Language2.ID_Person
WHERE Language1.ID_Language = [Forms]![Form1]![Combo22]
AND Language2.ID_Language=[Forms]![Form1]![Combo32]

The query builder will write the SQL if you can draw the joins properly.

Also, FYI, there are other ways to approach this problem. You can, for
instance, construct a system which lets you match on a variable number of
languages (instead of hard-coding exactly 3), and there are ways to avoid
referencing forms from your queries.
-Todd Matson
"Jenni" <je***@khul.com> wrote in message
news:40*********************@news.frii.net...
Hi all,

Sorry to hassle you with this query, I'm sure the answer is a simple
one, but it remains elusive - to me anyway.

What I am trying to do is get a query to work. I have a table of people
(with ID's) and a table of languages (with People IDs and Language IDs).
Now one person may speak many languages. I have put in the relationship.
What I want is to be able to say pull out all the people wjo speak these
3 languages.

The query I manage to make is this

SELECT DISTINCT People.ID_Person
FROM People INNER JOIN People_LanguageSkills ON People.ID_Person =
People_LanguageSkills.ID_Person
WHERE (((People_LanguageSkills.ID_Language)=[Forms]![Form1]![Combo22]));

The moment I add
AND (((People_LanguageSkills.ID_Language)=[Forms]![Form1]![Combo32]))

It stops working. It now says that no-one speaks English (ID 1) and
French (ID 3). I have checked to make sure that there are people in the
People_Languageskills table who have both languages:)

I have tried to select from only the People_Languageskills table and
from the joined tables as above.

What am I doing wrong????

Thanks in advance

Jenni

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #3

P: n/a
Jenni wrote:
Hi all,

Sorry to hassle you with this query, I'm sure the answer is a simple
one, but it remains elusive - to me anyway.

What I am trying to do is get a query to work. I have a table of people
(with ID's) and a table of languages (with People IDs and Language IDs).
Now one person may speak many languages. I have put in the relationship.
What I want is to be able to say pull out all the people wjo speak these
3 languages.

The query I manage to make is this

SELECT DISTINCT People.ID_Person
FROM People INNER JOIN People_LanguageSkills ON People.ID_Person =
People_LanguageSkills.ID_Person
WHERE (((People_LanguageSkills.ID_Language)=[Forms]![Form1]![Combo22]));

The moment I add
AND (((People_LanguageSkills.ID_Language)=[Forms]![Form1]![Combo32]))

It stops working. It now says that no-one speaks English (ID 1) and
French (ID 3). I have checked to make sure that there are people in the
People_Languageskills table who have both languages:)

I have tried to select from only the People_Languageskills table and
from the joined tables as above.

What am I doing wrong????

Thanks in advance

Jenni

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
A ; (semi-colon) ends a SQL statement. Are you appending the Combo32
line to the end of an existing SQL statement?

If you wanted a count of languages >= 3, you might want to consider
using DCount()
NumLanguages:Dcount("ID","People_LanguageSkills"," ID = " & [ID])
and substitute ID with your field name and in the criteria row enter2


Nov 12 '05 #4

P: n/a
The problem is that a single record cannot be both English and French.
It needs to be an OR criteria, however this won't return the results
you are looking for because you will get every person who speaks
english or french instead of English and French. So the work around
is to use the OR and then use a Group By with a Count of
People.ID_Person and only display the records where the
Count(People.ID_Person) is equal to the number of language skills you
are looking for.

SELECT DISTINCT People.ID_Person
FROM People INNER JOIN People_LanguageSkills ON People.ID_Person =
People_LanguageSkills.ID_Person
WHERE People_LanguageSkills.ID_Language)=[Forms]![Form1]![Combo22]
OR People_LanguageSkills.ID_Language)=[Forms]![Form1]![Combo32]
Group By People.ID_Person
HAVING Count(People.ID_Person)=2;

Jenni <je***@khul.com> wrote in message news:<40*********************@news.frii.net>...
Hi all,

Sorry to hassle you with this query, I'm sure the answer is a simple
one, but it remains elusive - to me anyway.

What I am trying to do is get a query to work. I have a table of people
(with ID's) and a table of languages (with People IDs and Language IDs).
Now one person may speak many languages. I have put in the relationship.
What I want is to be able to say pull out all the people wjo speak these
3 languages.

The query I manage to make is this

SELECT DISTINCT People.ID_Person
FROM People INNER JOIN People_LanguageSkills ON People.ID_Person =
People_LanguageSkills.ID_Person
WHERE (((People_LanguageSkills.ID_Language)=[Forms]![Form1]![Combo22]));

The moment I add
AND (((People_LanguageSkills.ID_Language)=[Forms]![Form1]![Combo32]))

It stops working. It now says that no-one speaks English (ID 1) and
French (ID 3). I have checked to make sure that there are people in the
People_Languageskills table who have both languages:)

I have tried to select from only the People_Languageskills table and
from the joined tables as above.

What am I doing wrong????

Thanks in advance

Jenni

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #5

P: n/a
Hi Todd,

I havnt been working with this since way back when, but I would love to
know how to reference a variable number of languages, and to do it
without referencing the form would be fantastic. I am a novice VB
developer, but find that I cant reference things in code in Access the
same way that I can in VB, which is very frustrating. I'd love to get
the info on the above.

Thanks,

Jenni

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.