How can i make this work?
SELECT * FROM item WHERE item_name LIKE '%' || (SELECT equipment_type FROM equipment_type GROUP BY equipment_type) || '%'
The inner sub query returns a list of strings like 'The' 'test' 'another' and i want to select all items from the item table where the item_name is similar to the sub queries return values. I need to have the wild cards.
Is there an alternative where i can use wildcards but use the IN sql command instead?
Subqueries can be used with SELECT, UPDATE, INSERT, DELETE statements along with expression operator. It could be equality operator or comparison operator such as =, >, =, <= and Like operator. A subquery is a query within another query. The outer query is called as main query and inner query is called as subquery.
CTE can be more readable: Another advantage of CTE is CTE are more readable than Subqueries. Since CTE can be reusable, you can write less code using CTE than using subquery. Also, people tend to follow the logic and ideas easier in sequence than in a nested fashion.
A multi-value subquery retrieves more than one value and has two forms of syntax, as shown below.
A subquery cannot be immediately enclosed in a set function. The BETWEEN operator cannot be used with a subquery. However, the BETWEEN operator can be used within the subquery.
You can use an INNER JOIN
:
SELECT I.* FROM item I INNER JOIN (SELECT equipment_type FROM equipment_type GROUP BY equipment_type) E ON I.item_name LIKE '%' || E.equipment_type || '%'
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