1

So I have a table

Books

id, name, organisationId, status

so, now what I want to get is the books with an organisationId as 3. which is ...

SELECT * FROM books where id= '3'

the problem is that I cant think of a way, where I could also get the books with status as public irrespective of organisationId.

I'm new to understanding mysql queries thats why I'm asking this so that I can understand.

1
  • 3
    Use AND / OR to add additional conditions to your WHERE clause. Commented Sep 24, 2018 at 11:42

4 Answers 4

3

use and with your where clause ,same way you could use or in place of and

SELECT * FROM books where id= 3 and status like '%public%'
Sign up to request clarification or add additional context in comments.

2 Comments

I think he should use OR because he want's to display "status as public irrespective of organisationId."
@boka18 i added that in description
3

Here is what you'll wanna do:

SELECT * FROM books where id= '3' OR status='public'

Comments

1

You should add OR with your posted query.

SELECT * FROM books WHERE id=3 OR status='public'

As you want to get all the info irrespective of id.

Comments

0

If you search for all books with organisationID=3 you need this statement:

SELECT * FROM books where organisationID= '3'

If you looking all books the either have organisationID=3 or status='public' you need this clause:

SELECT * FROM books where organisationID= '3' OR status='public'

Take a look a the SQL standards and/or the MySQL manual here: https://dev.mysql.com/doc/refman/8.0/en/select.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.