When using the Select by Attributes tool it creates a new layer. I don't need a new layer to be created and end up removing the created layer almost immediately. Is there a way to stop the tool from creating a new layer?
I'm not encountering this issue but it may help others offer some assistance if you provide the version of Pro you're using and what sort of feature is being selected (i.e. feature class, hosted feature layer, all data regardless of source, etc.), and lastly, if you're using the geoprocessing tool or simply using the "select by attributes" tool on the map ribbon.
Whenever I see strange behavior like this, I recommend doing a soft factory reset. You can follow the steps listed here. Once the reset is complete, open your *.aprx and try the Select by Attributes workflow again.
I am using version 3.2.2. The feature being selected is a feature class. Also I am using the Select by attributes on the map ribbon.
I'm using ArcGIS Pro 3.3 and seeing similar behavior to what was described by ZM258. In my case, I'm calling SelectLayerByAttribute with Python from a notebook being run within ArcGIS Pro. I could use the Python to delete the unwanted layer, but I'm also wondering if there's a way to turn this off if it's a setting or if this is 'unexpected' behavior. Based on this conversation, I think it must be unexpected. I don't remember it doing this before but I usually work on code outside of Pro. I just tried running the Select layer by attribute tool by hand (with the GUI interface) and it does not appear to add a new layer.
The code below adds 24 layers to the map. The SelectLayerByAttribute creates a layer with a copy of the original with the current month's data selected. The CopyFeatures creates the other 12 with only the selects, as expected.
for month in range(1,13):
where_clause = f"month='{month}'"
temp = arcpy.management.SelectLayerByAttribute("whale_points1", "NEW_SELECTION", where_clause)
byMonth = f"whales{month}"
arcpy.management.CopyFeatures(temp, byMonth)