Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

In MySQL, can I select columns only where something exists?

For example, I have the following query:

select phone, phone2

from jewishyellow.users

where phone like '813%'

and phone2

I'm trying to select only the rows where the phone starts with 813 and phone2 has something in it.

1 Answer

0 votes
by (40.7k points)

You can compare the value of phone2 with an empty string like this:

select phone, phone2 

from jewishyellow.users 

where phone like '813%' and phone2<>''

Note: Here, the NULL value is interpreted as false.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 29, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer

Browse Categories

...