3 ms·
I think that is the correct way to do it, you iterate over all the cats picking one cat at a time and it becomes quite obvious when you join a table to itself f
by danbruc 1y ago
I think that is the correct way to do it, you iterate over all the cats picking one cat at a time and it becomes quite obvious when you join a table to itself forcing you to do this. I am not writing that many SQL queries and I am certainly too lazy to always do that, especially if I am writing not too complicated ad hoc queries, but if I want the code to be as good as I can make it, then I always do this. Sure, it makes things a bit more verbose but you can also make the query more readable by picking a descriptive alias, FROM Users AS Manager, FROM Users AS NewEmployee, and so on.
- orphea 1y agoWhether you alias your plural tables to singular nouns would probably be one of the very last things I would check out if I would need to assess your code.
- danbruc 1y agoAnd you should not but I think it is still useful. You will probably not even become consciously aware of the difference but Cat.Name will be ever so slightly easier to read than Cats.Name and maybe that difference in cognitive load is what makes you spot some issue that you would have missed if your brain got repeatedly slightly tripped up by incorrect grammatical numbers.