Eduardo Eduardo - 1 year ago 176
SQL Question

SQL where term is equals or like (two tables)

With MySQL, I need to find all records where a column is like a term OR the term is equals a column but in another table.

For example:

select *
from table_a TA,
table_b TB
where TB.number = '1447'
or TA.subject like '%1447%'

In practice, I'm searching for a value, it can be on TB.number OR TA.subject. This SQL above is returning multiple records and it not matches the search.

Answer Source

Yeah, you need to do a JOIN among the table on a common column like

select * 
from table_a TA
join table_b TB 
on =
where TB.number = '1447' 
or TA.subject like '%1447%'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download