r/SQL • • Aug 27 '26

SQL Server Finding missing rows within the same table

Hello, I have a solution already but I think it can be done in a faster/neater way.

Let's say we have a table with: ORDER_ID, Article, Value.

For every order that comes in two rows end up in table, example:

ID_1, shoes, pair
ID_1, shoes, price

where price is being pulled from a different table.

I am looking for a way to find all ORDER_IDs that have only one row, because the price didn't exist in that other table so price row didn't form up. It doesn't throw a null value because of the way it's setup, if there is no price the row won't form at all!

I solved this with a standard left joining the table with itself, but I suspect there is a way to this easier?

3 Upvotes

23 comments sorted by

View all comments

Show parent comment

2

u/GRRRRRRRRRRRRRG Aug 27 '26

You can eliminate those extra rows in where section, just not include them. Anyway you need to know data to suggest something, and nobody knows it better than you. :)

1

u/SilaPrirode Aug 27 '26

I am still learning SQL, I would provide better examples if I knew how! xD
Any help is appreciated, I will try your suggestion :)

1

u/GRRRRRRRRRRRRRG Aug 27 '26

Just I have no idea what else is in the data. Like the initial post says about 2 rows per article, then you add information about extras. If you can distinguish extras from those 2 you were talking about, so it will be easy, as I already wrote, if you can't - you should give more info, or at least the query code that looks good to you on your data....