Joining two tables by a max or min value

B

Bob

I have two tables. The first has a group name and the
number of people in the group. The second has the maximum
number of people in a group size and group size code. i.e.
3 Size1(1-3 people)
6 Size2(4-6 people)
15 Size3(7-15 people)
50 Size4(16-50 people)

How can I build a query that will attach the correct group
size to my group name table?

Any help will be greatly appreciated.
 
C

Chris2

Bob said:
I have two tables. The first has a group name and the
number of people in the group. The second has the maximum
number of people in a group size and group size code. i.e.
3 Size1(1-3 people)
6 Size2(4-6 people)
15 Size3(7-15 people)
50 Size4(16-50 people)

How can I build a query that will attach the correct group
size to my group name table?

Any help will be greatly appreciated.

Bob,

Try:

Table1
GroupName
PeopleInGroup

Table2
GroupMin
GroupMax
SizeDescription

You need to have a new column here to delimit the minimum number of people
in a group, I called it GroupMin.


SELECT T1.GroupName
,T2.SizeDescription
FROM Table1 AS T1
INNER JOIN
Table2 AS T2
ON (T1.PeopleInGroup BETWEEN T2.GroupMin AND T2.GroupMax)



Sincerely,

Chris O.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top