可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
let's say i have this mysql table structure
:
table : articles ---------------- id content table : news ------------ id news
is there a way to search for a string in this two tables and then if the string occurs to return the table's name and the row id ?
回答1:
Assuming that the two tables have the same datatypes for id and news/content then a query along the lines of
SELECT id, 'articles' as tablename WHERE content like '%string to search for%' UNION SELECT id, 'news' as tablename WHERE news like '%string to search for%'
Should give you the result you're after
回答2:
You could try this:
SELECT 'articles' as table_name, id FROM `articles` WHERE content like '%<my_string>%' UNION SELECT 'news' as table_name, id FROM `news` WHERE news like '%<my_string>%'
回答3:
SELECT * FROM ( SELECT id, content as text, 'articles' as tablename FROM articles UNION ALL SELECT id, news as text, 'news' as tablename FROM news ) as tmp WHERE text = 'SEARCH_TERM'