Skip to main content
1 of 4

Selecting features in an ArcGIS attribute table based on values of other features in the same table using SQL

this is my first question on here so apologies if I break with any conventions.

I have a line feature class (saved in a feature dataset within a File GDB) which is comprised of a set of intersecting lines. I have used the Add Geometry tool to add Start_X, Start_Y, End_X and End_Y fields to the attribute table. The lines are not all orientated in the same direction, so for certain pairs of features in the table, End_X = End_X and End_Y = End_Y. I want to use the Select Layer By Attributes tool with an SQL query (if possible) to select only lines in the table with matching end coordinates and then run the Flip Line tool on the selection in order to reverse the direction of the selected lines. It's also worth noting that the OIDs are in a random order, e.g. line 1 may be connected to line 10.

Is it possible to use an SQL statement to select features in an attribute table based on the values of other features?

I tried SELECT * FROM table_name WHERE: END_X = END_X AND END_Y = END_Y AND OBJECTID <> OBJECTID

I'm sure it will be obvious to most that all that does is search each row individually and come up with nothing, though hopefully it gives an idea as to what I'm trying to do.

If it is not possible using SQL, is it something that could be done with Arcpy Search Cursors? (I am an extreme novice with Arcpy/Python scripting. I just know Search Cursors exist and can be used to find records in tables.)

Thanks in advance for any help.