I want to create a query from a list of values and return data for every match of cat
.
This works but it's not requiring the options
value. What's the easier way to query a list of values?
SELECT * FROM `table1` WHERE `option`='R' && `cat`='12' || `cat`='18' || `cat`='30'
mysql> select *from ListOfValues where Age IN(20,21,23,25,26,27,28) -> order by field(Age,20,21,23,25,26,27,28);
A list of commonly used MySQL queries to create database, use database, create table, insert record, update record, delete record, select record, truncate table and drop table are given below.
The most common way to get a list of the MySQL databases is by using the mysql client to connect to the MySQL server and run the SHOW DATABASES command. If you haven't set a password for your MySQL user you can omit the -p switch.
The first command you will need to use is the SELECT FROM MySQL statement that has the following syntax: SELECT * FROM table_name; This is a basic MySQL query which will tell the script to select all the records from the table_name table.
You can use the IN
operator
`cat` IN ('12', '18', '30')
You probably forgot to enclose those OR
parts into parentheses
SELECT * FROM `table1` WHERE `option`='R' and (`cat`='12' or `cat`='18' or `cat`='30')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With