SQL, selecting items with specific pattern | Sololearn: Learn to code for FREE!

+1

SQL, selecting items with specific pattern

I would like to select all names contain letter ‘g’ from a table, the names can be started with g, g in between or end with g. Which query is most suitable? Query 1: SELECT * FROM table WHERE Name LIKE ‘%g%’; Query 2: SELECT * FROM table WHERE Name LIKE (‘g%’ OR ‘%g%’ OR ‘%g’);

sql

5/3/2019 1:39:36 AM

Poo

1 Answer

New Answer

+4

I think query 1 is better as it's short and simple. It simply means that get that row from table where this field contains 'g', no matter where it is i.e. irrespective of its index in string.