- Jun 7, 2000
- 9,099
- 19
- 81
Note the following tables:
Table pr describes the relationship between people pv and attributes that may apply to those people code. Each person pv_id may have zero or more attributes (rows) code_id in pr.
When I'm asking for detail of the associations, I might use a query like this:
What I need to do now, though, is select the pv.pv_id and code.code_id per code.type where code.weight is either (the least number appearing OR null). For example, while referring to the following result set from the above select query:
I need to build a query to determine the following result set:
I've done something similar to this previously, but I don't currently have access to those statements, and I'm apparently having a bad day cause I can't think of any way to do this without a really ugly solution involving multiple nested queries.
Does anyone have any suggestions?
Thanks!
pv
pv_id (PK)
pr
pv_id
code_id
code
code_id (PK)
type
message
weight
Table pr describes the relationship between people pv and attributes that may apply to those people code. Each person pv_id may have zero or more attributes (rows) code_id in pr.
When I'm asking for detail of the associations, I might use a query like this:
SELECT pv.pv_id, code.code_id, code.type, code.message, code.weight
FROM pv
INNER JOIN pr ON pv.pv_id = pr.pv_id
INNEER JOIN code ON pr.code_id = code.code_id
What I need to do now, though, is select the pv.pv_id and code.code_id per code.type where code.weight is either (the least number appearing OR null). For example, while referring to the following result set from the above select query:
1, 32, GREETING, WELCOME, 1
1, 33, GREETING, HELLOTHAR, 2
1, 34, GREETING, WHATSUP, NULL
1, 35, GREETING, LEAVEMEALONE, 3
I need to build a query to determine the following result set:
1, 32, GREETING, WELCOME, 1
1, 34, GREETING, WHATSUP, NULL
I've done something similar to this previously, but I don't currently have access to those statements, and I'm apparently having a bad day cause I can't think of any way to do this without a really ugly solution involving multiple nested queries.
Does anyone have any suggestions?
Thanks!
