H
H
hdtor2016-04-05 14:28:58
PHP
hdtor, 2016-04-05 14:28:58

How to fix a query in the database?

I have a table in the database, it has two enum fields:
1. photo = has the values ​​yes or no
2. video = has the same values ​​yes or no
There is a task to write a query that would select all records that have photo or video marked with the value yes .
So far I've thought of this:

$result = $mysql->query("SELECT * FROM news WHERE photo = 'yes' AND video = ' yes'");

But there is one problem, the query selects all records in which two fields have the value yes.
How to rewrite it to select all records, even if video = 'yes' in one record, and photo = 'no' in another record... ?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vladimir Martyanov, 2016-04-05
@vilgeforce

Do you understand the difference between AND and OR?

A
Alexey, 2016-04-05
@al_mak

photo = 'yes' AND video = ' yes'
gives records where photo and video are both yes
photo = 'yes' OR video = ' yes'
gives records where either photo and video are both yes or either of the photo and video fields is yes

T
Timur Sergeevich, 2016-04-05
@MyAlesya

result = $mysql->query("SELECT * FROM news WHERE photo = 'yes' OR video = ' yes'");

D
Dmitry Eremin, 2016-04-05
@EreminD

result = $mysql->query("SELECT * FROM news WHERE photo = 'yes' OR video = ' no'");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question