Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mySQL query select column where value = a or value = b etc

Tags:

mysql

How do I write a mysql query so that I can select entries under a column that are equal to resultA or resultB or resultC etc.

Something like:

SELECT * FROM myTable WHERE myColumn = resultA OR WHERE myColumn = resultB OR WHERE myColumn = resultC...
like image 721
user2755541 Avatar asked Mar 20 '14 19:03

user2755541


People also ask

How do you check if a column contains a value in MySQL?

$query = "SELECT * FROM my_table WHERE categories LIKE '2'"; $rows = mysql_query($query); This returns row if column only has value 2 but not 1,2,3 or 2,12.

How do I match two columns in MySQL?

Here's the generic SQL query to two compare columns (column1, column2) in a table (table1). mysql> select * from table1 where column1 not in (select column2 from table1); In the above query, update table1, column1 and column2 as per your requirement.

Which clause in MySQL indicates which columns?

The SET clause indicates which columns to modify and the values they should be given. Each value can be given as an expression, or the keyword DEFAULT to set a column explicitly to its default value.

How do you select a column by value?

Click the top edge of the column header or the column in the table. The following selection arrow appears to indicate that clicking selects the column. Note: Clicking the top edge once selects the table column data; clicking it twice selects the entire table column.


1 Answers

SELECT *
FROM myTable
WHERE myColumn = 'resultA' 
   OR myColumn = 'resultB' 
   OR myColumn = 'resultC';

Alternatively,

SELECT *
FROM myTable
WHERE myColumn IN ('resultA', 'resultB', 'resultC');
like image 96
keelerm Avatar answered Sep 27 '22 19:09

keelerm