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.
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.
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.
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.
SELECT * FROM products WHERE catid IN ('1', '2', '3', '4')
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