Equals(=) vs. LIKE

后端 未结 15 1994
情书的邮戳
情书的邮戳 2020-11-22 15:19

When using SQL, are there any benefits of using = in a WHERE clause instead of LIKE?

Without any special operators, LIKE

15条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 15:30

    Using = avoids wildcards and special characters conflicts in the string when you build the query at run time.

    This makes the programmer's life easier by not having to escape all special wildcard characters that might slip in the LIKE clause and not producing the intended result. After all, = is the 99% use case scenario, it would be a pain to have to escape them every time.

    rolls eyes at '90s

    I also suspect it's a little bit slower, but I doubt it's significant if there are no wildcards in the pattern.

提交回复
热议问题