Finding SQL Rows With Similar Values

Databases

05/07/2021


Let me first clarify what I mean by similar values. Imagine the following Users table containing emails and names:

IdEmailName
1jack@gmail.comJack
2mike@gmail.comMike
3anna@yahoo.comAnna
4stan@qq.comStan
5sara@gmail.comSara

How would we go about retrieving all Gmail emails? Allow me to introduce you to LIKE. 🤗 This command enables you to perform some basic pattern matching.

SQL
SELECT * FROM Users WHERE Email LIKE '%gmail%';

Outputs:

IdEmailName
1jack@gmail.comJack
2mike@gmail.comMike
5sara@gmail.comSara

After LIKE, simply enter the common value you'd like to find.

% serve as a catch-all symbol, meaning it will match any character. For instance, %gmail will only match with values that has any kind and any amount of characters preceding the word gmail, but none following it.


WRITTEN BY

Code and stuff