If value is zero don't check in where statement?2018-03-22 mysql
I want to check if a value matches another, but only if that value is not zero. The first two examples would be considered in the where statement, but not the third. I was trying to see if an if statement would work, but I don't know where to begin.
Example of a match: column1 = 'theredroof' column2 = 'theredroof' Example of non match: column1 = 'theredroof' column2 = 'thegreenroof' Example of exclusion: (I don't want it to consider this in the where statement at all) column1 = 'theredroof' column2 = 0 OR column1 = 0 column2 = 0
Here is an example of the mysql query:
SELECT `books`.* FROM `books` LEFT JOIN issues ON issues.id = books.issue_id LEFT JOIN titles ON titles.id = issues.title_id LEFT JOIN lists ON books.id = lists.book_id WHERE ( lists.customer_id = '900001' AND lists.volume = issues.volume AND `books`.`status_id` = '3' AND `books`.`deleted` = "0" ) GROUP BY `books`.`id`
So if lists.volume = 0 I don't want it to be checked in the where statement.
select column1, column2, if (column1 = column2, 'match', 'not matched') matched from x where column1 <> 0 and column2 <> 0
- SQL - Trying to tell which part of a query was matched with an 'OR' statement
- Replace Default Null Values Returned From Left Outer Join
- 'IF' in 'SELECT' statement - choose output value based on column values
- INNER JOIN ON vs WHERE clause
- Which MySQL data type to use for storing boolean values
- Finding duplicate values in MySQL
- Delete sql rows where IDs do not have a match from another table
- MySQL Query > Select future rows and check if specific column is filled AND matches variable > else take other column if it matches variable
- Where is the mysqli prepared statement query error?
- Test for NULLs in multiple columns in MySQL