r/DatabaseHelp • u/NotSeanPlott • Feb 21 '17
What is faster? Does it matter?
Hello Again everyone!
I have a question about ways to query: http://imgur.com/a/X1nvt
That links to a example table setup and ERD.
The database stores either the AccountID or ContactID, this validation is done by the application I assume.
Again I'm a noob and I'm curious which approach I should take. I need to access either the Contacts Fullname or the Accounts Name.
I believe have two options, either use:
- Case
When order.CustomerType = 1 then account.name
When order.customertype = 2 then contact.fullname
End
2.isnull(account.name, contact.fullname)
Would one approach be more efficient? The benefit I see of option 1 is if the Application's validation fails and there are two values, or more customer types are added.
I'd appreciate your thoughts!
Thanks!
View all comments
Show parent comment
2
u/NotImplemented Feb 22 '17
This is important! Never try to optimize without checking the query plan and measuring first.