i have two tables "members" and "users".
开发者_开发知识库I need with one query from this two tables get all users where condition is "name LIKE %Joy%
".
How join in this situation two tables?
Tables:
users
id / name / age
1 joy 15
2 marko 26
members
id / name / level
1 peter 1
2 joyes 0
3 marko 1
Try with UNION
. I added the first column so you can check later where that result came from (and create a link to the user's profile page for example).
(SELECT 'user' AS type, id, name FROM user WHERE name LIKE '%Joy%')
UNION
(SELECT 'member', id, name FROM member WHERE name LIKE '%Joy%')
It appears as though both tables essentially store information about the same kind of thing: people. I don't know what the difference is between a "user" and a "member" in your specific situation, but it sounds as though you might be better off having just one table "people" with a bit column specifying whether the person is a user or a member.
精彩评论