Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a 'naked where clause'

Tags:

sql

In a conversation with my coworker, he mentioned he accidentally deployed a 'naked where clause' into production.

What is a 'naked where clause'?

like image 418
Chuck Conway Avatar asked Mar 07 '13 17:03

Chuck Conway


1 Answers

a naked WHERE clause would refer to something that always returns true

WHERE 1 = 1

This is commonly used on something like a search form where the user can enter one or many values and rather than checking a counter to see if you need to add a WHERE clause you add a generic WHERE clause and build everything up in an AND clause. You can run into issues if you aren't checking to make sure there is at least on AND clause added.

like image 117
Matt Busche Avatar answered Nov 07 '22 00:11

Matt Busche