How to join two tables based on substring values of fields?

后端 未结 4 663
予麋鹿
予麋鹿 2021-01-05 07:34

I am having problem with sql. I want to join two tables, employee and class instructor. Condition is that employee is having unid column like \'u0871457\' where as class i

4条回答
  •  情歌与酒
    2021-01-05 08:22

    Oracle uses 1 as the base of its indexes, so substr('aaa',1,3) is equivalent to 'aaa'. You need to use 2 as the second parameter of substr in order to accomplish what you're attempting.


    Beyond that, you'd probably be better off only changing one side, if you can. If the prefix characters are consistent, you could do this:

    SELECT e.name, i.name
    FROM   employee e INNER JOIN instructor i ON REPLACE (e.id, 'u', '0') = i.id
    

    This would potentially allow the database to use an index on instructor, which would not be possible with your solution.

提交回复
热议问题