Skip to content
Advertisement

how does ‘ ‘ i.e single quote space single quote work in sql?

I observed that this query returns all values from the database.

SELECT * FROM projround3.add_user where user_email like '%' '%';

Why is that?

Advertisement

Answer

This query:

SELECT *
FROM projround3.add_user
WHERE user_email like '%' '%';

Would not be valid in most databases. Some interfaces concatenate adjacent strings, so this is interpreted as:

SELECT *
FROM projround3.add_user
WHERE user_email like '%%';

The two wildcards are the same as one. This will match every non-NULL value.

If you want to find emails with a space, then correct logic is:

SELECT *
FROM projround3.add_user
WHERE user_email like '% %';
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement