I have tables with this structure.
table #1: users (ID, user_name)
1, 'john777'
2, 'andy'
3, 'tom'
table #2: user_meta (meta_ID, user_ID, ‘meta_name’, ‘meta_value’)
1, 1, 'first_name', 'John'
2, 1, 'last_name', 'Smith'
3, 2, 'first_name', 'Andy'
4, 2, 'last_name', 'Pete'
5, 3, 'first_name', 'Thomas'
6, 3, 'last_name', 'Tan'
7, 3, 'other_random_meta', 'abcxyz'
For you guys familiar with WordPress, this is their database structure.
What I want to do is to get the user IDs of users matching my search term based on the user_name and full name, made up of first_name and last_name.
In other words, I want a search to return 1 for these search terms:
‘joh’, ‘john7’, ‘smith’, ‘john smi’, ‘smith jo’
This should get you the Unique user ID’s that match your search criteria
will return all users matching your criteria. Duplicates are not eliminated and returned as is.
To get a single row indicating the number of matches use
SELECT COUNT(*) â¦
and to only get 0 or 1 useSELECT COUNT(*) > 0 â¦
Okay, new query. If you want the IDs of matching users, you have to JOIN the two tables together: