vendredi 2 janvier 2015

SQL(ite) JOIN with regex within JOIN

I have two tables both with a column called Name. Sometimes the names begin with an uppercase letter whereas other times not. I would like to join the two tables on the names so that bob's match the Bob's. I assume that this could be possible with regular expressions, so how can one construct an SQL JOIN query that does do this match and what is the correct regex?


For example: Say I have table1 as :



Name| col1
----------
Bob | a
Jon | b


and table 2 as:



Name| col2
----------
bob| c
Jon| d


I would join them as follows (with xx being the missing regex and yy being the correct selection)



SELECT * , yy as NameWithCapAtFront
FROM table1 as t1
LEFT JOIN table2 as t2
ON xx(t1.Name)=xx(t2.Name)


but this misses the bob match with Bob.


Further, how would one always select capitalised version of the Name.


Aucun commentaire:

Enregistrer un commentaire