SQL Tip: Avoid Applying Functions to Table Data

You may also like...

4 Responses

  1. Dick Rietveld says:

    Love it when I read “left of my comparison operator”.
    I also code: [code]
    select lastname from employee a where a.firstnme = ‘JOHN’ [/code]
    But sometimes I see SQL like this: [code]
    select lastname from employee a where ‘JOHN’ = a.firstnme[/code]
    It looks very odd to me, but it seems to work as well. I never found arguments why the db-column should be on the left…. Are there?

    • Roland says:

      Hi Dick,

      the ‘other way round’ is mostly a coding pattern to prevent unintentional assignment, when there is an assignment operator ‘=’ and a comparison operator ‘==’. Some people do it even here… 😉


  2. Bobby says:

    Nice article. Well done Ember!

Leave a Reply

Your email address will not be published. Required fields are marked *