Kafonek
Kafonek

Reputation: 372

sqlite - add wildcards to a column reference

Say I have two tables (in sqlite, which I can't change) along the lines of -

table1 -
first_name, last_name
Joe, Schmoe
Monty, Python

table2 -
full_name, job_title
Joe Schmoe, professional stackoverflow question-creater
Monty Python, Flying Circus

How do I craft a query in sqlite to end up getting the job_title for an entry from table1? Intuitively, something like "select table1.first_name, table2.job_title from table1, table2 where table2.full_name like table1.first_name + '%'"

I've tried fiddling with CONCATENATE(table1.first_name, '%') and couldn't get it to work. Thanks in advance.

(edited to try and clean up the format a bit)

Upvotes: 0

Views: 237

Answers (1)

Raphaël Althaus
Raphaël Althaus

Reputation: 60493

|| is the concatenation operator in Sqlite

So you may do something like that.

select t1.first_name, 
       t2.job_title
FROM Table1 t1
INNER JOIN Table2 t2 
      ON t1.firstName||' '||t1.LastName = t2.full_name

Useless to say it's a bad way to manage your data (but if you can't change)...

Upvotes: 0

Related Questions