Here I am struggling with SQL
I made a search bar that can match with three different rows in sql. Problem, one of these rows isn't in the same table as the two others.
Here is an example
TABLE 1 : topics
id || name || category || id_merchant
1 || football || Sports || 1
2 || marmalade || cooking || 2
3 || Hitchcock || cinema || 3
TABLE 2 : merchant
id || merchant
1 || NIKE
2 || Cooking Corp
3 || GoodFilms Corp
PROBLEM with this request (when I'm searching for "Corp" keyword) :
SELECT T.name, T.category, M.merchant
FROM topics AS T,
merchant AS M
WHERE T.name LIKE '%Corp%'
OR T.category LIKE '%Corp%'
OR M.merchant LIKE '%Corp%'
AND T.id_merchant = M.id
It returns all the merchant that "Corp" in there names, but I only want to retrieve a topic that have a merchant matching with "Corp"
Then I tried this :
SELECT T.name, T.category, M.merchant
FROM topics AS T,
merchant AS M
WHERE T.name LIKE '%Corp%'
OR T.category LIKE '%Corp%'
OR (SELECT M.merchant WHERE M.id = T.id_merchant) LIKE '%Corp%'
AND T.id_merchant = M.id
But it returns a syntax error.
Hope I was clear enough.
Thank you in advance!