Say I've two tables products and brands having below data.
tbl_products ID Name BrandID Price 1 Keyboard 1 100 2 Keyboard 2 120 3 Keyboard wireless 1 130 4 Keyboard wireless 2 150 tbl_brands ID Name 1 Microsoft 2 Dell 3 HP
What I want is when I type 'Microsoft Keyboard' or 'Keyboard Microsoft' then it should list me product ID 1 and 3 not 2 or 4 even 2 or 4 has keyboard. I may search for more keywords but it should give me only the items matching itself.
SELECT p.*, b.Name BrandName FROM tbl_products p INNER JOIN tbl_brands b ON b.ID = p.BrandID WHERE p.Name LIKE '%Microsoft%' OR b.Name LIKE '%Microsoft%' OR p.Name LIKE '%Keyboard%' OR b.Name LIKE '%Keyboard%'
Please help me to write proper MySQL query or any schema change with query..