Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SCRIPT HELP!

Status
Not open for further replies.

mkey

Programmer
Oct 3, 2001
288
CA
Hi All,
My two table data looks something like this:
table_a:

id key input
1300 1 1201
1300 2 1300
1300 3 1400
1400 1 1100
1400 2 1000

table_b:

id key input
1300 1 500
1300 2 1300
1300 3 1400
1400 1 1200
1400 2 1000

I want compare the input values between table_a and table_b. The values should be equal when the id and minimum key value and maxinum key value is the same in both table_a and table_b.
The output I need:
id key input
1300 1 500
1400 2 1000
Thank you!!
 
I don't think your example matches your description.

"The values should be equal when the id and minimum key value and
maxinum key value is the same in both table_a and table_b."

What does this mean?

For id = 1300 you have

table_a table_b
id key input id key input
1300 1 1201 1300 1 500
1300 2 1300 1300 2 1300
1300 3 1400 1300 3 1400

and you say in your example that the results should be:

id key input
1300 1 500

Now in the data, the min/max id/key values are
1300/1 and 1300/3, respectively.
So the corresponding input values are 500/1201 and 1400/1400, respectively.
Why do you only want 1300/1/500? And where is the equality here?

Please expand on your problem.

 
I want 1300/1/500 because when the id is 1300 and min value 1 for both tables the input does not equal each other. So I want to output that values. When 1300/3/1400 both tables's input values matches. So in that case I do not want to output the id/key/input values.
Does this make sence. Sorry for any confusions Carp.
Thank you!!!!
 
It sounds like what you want is:

SELECT a.id, a.key, a.input
FROM table_a a, table_b b
WHERE a.id = b.id
AND a.key = b.key
AND a.input <> b.input
AND a.key = (SELECT min(key)
FROM table_a
WHERE table_a.id = a.id);

I didn't test this, so it may not work, but I THINK it will do the job for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top