Search code examples
sqlselectprestocase-when

SQL: Select rows if it fuzzy matches with corresponding column


I have a data frame which has 2 columns

**Job**    **Station**
Service      ServiceA
Wash         ServiceA
Service      WashA
Service      ServiceA
Wash         WashA
Wash         WashB 
Wash         Invoice
Wash         Entry
Service      Invoice
Service      Entry

Job takes values Service or Wash whereas Station takes values ServiceA, ServiceB, WashA, WAshB. There are entries corresponding to Job 'Service' as 'WashA' which is incorrect as Service should correspond to only ServiceA or ServiceB. Entry and Invoice should stay for every job. I want to select the rows which are only correctly mapped.

How can I do that?


Solution

  • I suspect you want:

    select t.*
    from t
    where station like concat(job, '%')
    

    This checks that the leading characters in station match job.