Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL select everything in an array

Tags:

sql

select

My homework has a problem for example there is a category array $cat=array('1','4','5','7'); now i need to select products from db based on the category that is

SELECT * FROM products WHERE catid='1' SELECT * FROM products WHERE catid='4' SELECT * FROM products WHERE catid='5' SELECT * FROM products WHERE catid='7' 

Is it possible to do this in a single query? as the final results of the four queries will be combined.

like image 337
bluedream Avatar asked Apr 01 '11 00:04

bluedream


People also ask

How do I select all elements in SQL?

In its most simple form, the SELECT clause has the following SQL syntax for a Microsoft SQL Server database: SELECT * FROM <TableName>; This SQL query will select all columns and all rows from the table.

How do I query an array of columns in SQL?

Step 1: Group the data by the field you want to check. Step 2: Left join the list of required values with the records obtained in the previous step. Step 3: Now we have a list with required values and corresponding values from the table.

Can we use array in SQL query?

The ARRAY function returns an ARRAY with one element for each row in a subquery. If subquery produces a SQL table, the table must have exactly one column. Each element in the output ARRAY is the value of the single column of a row in the table.


1 Answers

SELECT * FROM products WHERE catid IN ('1', '2', '3', '4') 
like image 150
Senthil Avatar answered Oct 02 '22 15:10

Senthil