DEV Community

Simon Foster
Simon Foster

Posted on • Originally published at funkysi1701.com on

Happy Christmas

I saw this tweet on twitter.

He’s making a database,
He’s filtering twice
SELECT * FROM customers WHERE behaviour = Nice
Santa Clause is Coming to town.

Enter fullscreen mode Exit fullscreen mode

This started me thinking surely in a normalized database structure behaviour wouldn’t be stored in the customer table, so I propose the following change.

He’s making a database,
He’s filtering twice
SELECT * FROM customers WHERE EXISTS (select * from behaviour where behaviour.CustomerId = customers.Id and behaviour.Type = Nice)
Santa Clause is Coming to town.

Enter fullscreen mode Exit fullscreen mode

Happy Christmas everyone, hope you all have restful holidays.

Top comments (0)