-2

I have 2 tables. One of them having one of the columns as regexp's. I want to join the two tables on the regexp column. Cannot seem to be able to do this. To elaborate: table 1 is (errortype, action, error message) and table 2 is(regexp for error message of each type, error code) join columns are error message and regexp, both string. Is this possible? Thanks.

Select * from table1 
left outer join table2 on table1.error_message=table2.regExp. 

Issue : table2.regExp has actual regular expressions that should match one or more table1.error_messages. the = does not work here.

  • Sample data and desired results would clarify what you want to do. – Gordon Linoff Jul 30 '20 at 14:32
  • New users should take the [tour](https://stackoverflow.com/tour), then visit the [help center](https://stackoverflow.com/help) and in your case, I suggest also reading [How do I ask a good question](https://stackoverflow.com/help/how-to-ask). Then you should [edit] your question according to the information in the above links. So regarding your question: Do you want to see which rows in table 1's _error message_ column are matched by the regexp in table 2? – Abra Jul 30 '20 at 14:52

1 Answers1

0

You need to use the REGEXP or RLIKE operator. = performs exact matches, not pattern matching.

SELECT *
FROM table1
LEFT OUTER JOIN table2
ON table1.error_message REGEXP table2.regexp
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Thanks Barmar, in that case when I am storing the data in table2, the regexp, should I be inserting it with ' (quotes), because REGEXP would need the second string to be in quotes? – Snehal Jadhav Jul 30 '20 at 18:25
  • Yes, just like any other string. – Barmar Jul 30 '20 at 18:30