Reputation: 3092
The following query returns
"single-row subquery returns more than one row"
select * from sampleTable
where
status = 'A'
and (SELECT SUBSTR(some_code_column, 1, 4) from sampleTable) = 9999
I need to fetch all the rows of the table where status is A and All the rows with SUBSTR(some_code_column, 1, 4) = 9999
How to change the query so that it fetches the required result?
Upvotes: 1
Views: 117
Reputation: 537
You want both the conditions to get true or any of them?? In case any of them then please use OR
instead of AND
Upvotes: 0
Reputation: 15071
This was before you clarified you wanted to return data that satisfies both conditions not one or the other.
I would use a UNION
in this scenario.
SELECT *
FROM sampleTable
WHERE status = 'A'
UNION
SELECT *
FROM sampleTable
WHERE SUBSTR(some_code_column, 1, 4) = 9999
More reading on performance here https://stackoverflow.com/a/13866221/2641576
Upvotes: 2
Reputation: 44766
No need for that sub-select, simply AND the conditions:
select * from sampleTable
where
status = 'A'
and SUBSTR(some_code_column, 1, 4) = 9999
Upvotes: 1