Can't figure out how to get rows based on column values that aren't identical
My problem is this:
Say I hypothetically have a table called fas开发者_开发百科tfood which has one field called fastfood_chains that have values of "Awesome Wendys" and "Peanut Chuck"
Then I have another table called fastfood_info that has a field "fastfood_chain" but the values aren't identical to the other table, it's shortened to "Wendys" or "Chucks"
How would I display all the rows from fastfood_chain and have the results print the full name using the other table instead of just "Wendys" or "Chucks" ?
I assumed it had something to do with the LIKE statement but I'm having difficulties. Any help would be appreciated.
If You know that fastfood_chain in second table contains only subsets of fastfood_chain from first table. I didn't quite understand what exact columns do You want in the result, but You can list them with fff and ffc prefix:
SELECT * FROM fastfood_chains ffc
INNER JOIN fastfood_info ffi ON
ffc.fastfood_chain LIKE CONCAT('%', ffi.fastfood_chain, '%')
Please note that this might be extremely slow depending on many factors.
P.S.: I don't have access to MySQL instance at the moment. Hope it works now. For MSSQL users, the last line should be:
ffc.fastfood_chain LIKE '%' + ffi.fastfood_chain + '%'
Possible way of doing this is:
SELECT F.FASTFOOD_CHAIN, I.*
FROM FASTFOOD F
LEFT OUTER JOIN FASTFOOD_INFO I
ON F.FASTFOOD_CHAIN LIKE '%' || I.FASTFOOD_CHAIN || '%'
精彩评论