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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query problem?

Status
Not open for further replies.

FranckM

Programmer
May 8, 2002
76
CA
I'm trying to get a list of all the numbers for which the parent of that number and the parent of that numbers formers aren't the same.

Every number has a parent. A number can also have a forward( a number that was create before the current number was created) number and a former number( a number that was create after the current number was created).

The list of all the numbers is in the table other_table. The parent, former and forward numbers are in the parent_table.

This is what I came up with

select p.num, ps.former, ps2.former, ps3.former_pin
from ilrs.parent_table ps, ilrs.other_table p, ilrs.parent_table ps2, ilrs.other_table p2, ilrs.other_table p3, ilrs.parent_table ps3
where p.num = ps.forward
and ps.parent = 1
and p.num = p2.num
and p2.num = ps2.forward
and ps2.parent = 0
and p2.num = p3.num
and ps3.parent = 1
and ps3.former <> ps.former
and ps.former <> ps2.former

This is the result I get. Only the last field is changing and this goes on for many records 20000+ Is there a problem in the logic of my sql statment?

402010135 402017173 402017180 602004558
402010135 402017173 402017180 402012172
402010135 402017173 402017180 402002841

Thanks for taking a look at this.
 
You may have missed a join in the query &quot;and p3.num = ps3.forward&quot;.

If that doesn't fix it, can you an example of data from the parent_table and the other_table.

Barb
 
Thank you very much, it wasn't former, but forward,but that was the problem. Thanks ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top