Does my query follow correct format? I can't find any examples of using LIKE and ON, so I am not sure if my query is the problem. Looking for any suggestions or feedback:
SELECT *
FROM table_1 a
LEFT JOIN table_sql ON a.case_id LIKE '%45305%'
Does my query follow correct format? I can't find any examples of using LIKE and ON, so I am not sure if my query is the problem. Looking for any suggestions or feedback:
SELECT *
FROM table_1 a
LEFT JOIN table_sql ON a.case_id LIKE '%45305%'
This is not correct, you need to specify which column you want to use for the JOIN, but you can do something like this
SELECT * from table_1 AS a
LEFT JOIN table_sql AS b
ON a.case_id = b.id
WHERE
a.case_id LIKE '%45305%'
Since you want to use LIKE
instead of =
, is this what you want?
SELECT * FROM table_1 a
LEFT JOIN table_sql ON
a.case_id LIKE CONCAT('%', table_sql.case_id, '%')
See also #4420554
You can use LIKE in a join, but it sounds like what you you really want is a UNION:
SELECT case_id
FROM table_1 a
WHERE a.case_id LIKE '%45305%'
UNION
SELECT case_id
FROM table_sql s
WHERE s.case_id LIKE '%45305%'
If you need to keep track of which table the result came from, you can do something like:
SELECT 'table_a' AS what_table, case_id
FROM table_1 a
WHERE a.case_id LIKE '%45305%'
UNION
SELECT 'table_b', case_id
FROM table_sql s
WHERE s.case_id LIKE '%45305%'
Try this, using CONCAT()
. it was helpful for me, when I was selecting the full table data:
SELECT p.post_name,p.post_title,p.post_type,cl.*
FROM ".$wpdb->posts." AS p
LEFT JOIN clicks AS cl
ON cl.podcast_url LIKE CONCAT('%',p.post_name,'%')
WHERE p.post_type = 'team'