I have the below sql, which if i take out the inner join to the table and hard code the values, i get 2 records. But when i use the inner join statement, i just get 1 record. I am aware that with MYSQL, the like clause, is not case sensitive. Here is the sql below. I dont know why it is only returning row.
SELECT
a.project_code as projectCode,
a.project_name as projectName,
a.project_creation_date as projectCreationDate,
a.project_end_date as projectEndDate,
a.project_status as projectStatus
from projects a
inner join tmp_rec_naren8 b
on a.project_name like concat("%",b.expertise_desc,"%")
OR a.project_description like concat("%",b.expertise_desc,"%") ;
If I change the above to:
select *
from projects
where project_name like '%java%'
OR project_description like '%java%';
I get 2 rows and not 1.
Table tmp_rec_naren8 has just one column expertise_desc and contains this data:
expertise_desc
--------------
XML
Python
DWH
Java
Table projects has many columns :.. But these below are the relevant ones
project_code sr_user_name project_name project_descriiption ..
-----------------------------------------------------------
1 naren5 POS C++, XML,Java
2 naren7 INV Networking
3 naren9 CCV Java, Unix
The first query returns 1 row:
project_code sr_user_name project_name project_descriiption ..
---------------------------------------------------------------
1 naren5 POS C++,XML,Java
The second query returns 2 rows
project_code sr_user_name project_name project_descriiption ..
-----------------------------------------------------------
1 naren5 POS C++, XML,Java
3 naren9 CCV Java, Unix
One explanation would be if the value in
expertise_desccontained a trailing space, ie'Java '(not'Java'). Then the concat value would be'%java %', not'%java%', making a difference.If one of your project names ended with
java, and the other hadjavawithin the name, only one would match using the join, but two would match with the non-join.