Cheknov
Cheknov

Reputation: 2082

What is the most standard criteria for 'partial match' in sql select queries?

I have been asked that the queries to the database be partial match.

Generally, to use partial match with LIKE we need to know which wildcard we are going to use for pattern matching, right?.

My question is: is there a 'generic' case to apply partial match without having any specific constraints?

This is an example query that I use in my project, could someone give me an example of how to do this query 'partial match' without any specific constraints?

select
    a.*,
    coalesce(nullif(a.aachange, '.'), nullif(a.detailref, '.') ) as var,
    b.*,
    c.*
from
    db-dummy.data c
join db-dummy.info a on
    a.record_id = c.var_id
join db-dummy.s_data b on
    b.record_id = c.s_id
order by
    a.g_name;

UPDATE:

I am going to add more information about the desired output.

Let's say I have a column:

+------------+
|    Col     |
+------------+
| ABCDEFG    |
| ABCDEFGH   |
| ABCDEFGHI  |
| AB12398JKH |
+------------+

If Where Col = 'AB', the result should be: ABCDEFG, ABCDEFGH, ABCDEFGHI, AB12398JKH

If Where Col = 'ABC' the result should be: ABCDEFG, ABCDEFGH, ABCDEFGHI

If Where Col = 'ABCDEFGH' the result should be: ABCDEFGH, ABCDEFGHI

If Where Col = 'ABCDEFGHI' the result should be: ABCDEFGHI

Upvotes: 0

Views: 243

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270573

You seem to be looking for LIKE:

where col like concat('AB', '%')

You can pass in the 'AB' as a parameter. Or set the parameter up with the wildcard ('AB%').

Upvotes: 1

Related Questions