Reputation: 1345
How do I count rows where a column value starts with a another column value ?
For example, I have table products shown below
---------------------------
id code abbreviation
---------------------------
1 AA01 AA
2 AB02 AB
3 AA03 AA
4 AA04 AB
---------------------------
I want to get the count of products whose code starts with abbreviation. A query like this
select count(*) from products where code ilike abbreviation+'%'
I am using postgresql 9.5.3
Upvotes: 0
Views: 1107
Reputation: 146
The string concatenation operator in postgresql is: ||
select count(*) from products where code like abbreviation || '%';
Upvotes: 4
Reputation: 845
You can try:
select count(*) from products where code like '%'+abbreviation+'%'
But i am not sure why do you need this type of query.
Upvotes: -1