I have an app where user phone book uploaded on server same like whatsapp,telegram,facebook etc.
User imported phone book structure look like this
Table Name: PhoneBook
id user_id first_name mobile(Varchar(20))
1 100 John +91981000000
2 100 Tom 91981000001
3 100 Ron 9810-000-02
4 100 Mat 91981000003
5 100 Miley 981000004
Table Name: Registered_User (Main Table For Existing Users)
ID Name Phone (Varchar(20))
1 Sam 09811111111
2 Abby 919811000000
3 Ben +19854646464
4 Tom +91981000001
5 Ron 981000002
6 Sam 981111145
So When user wants to see how many friends of my existing contact on the app then first i need to grab all contacts of user with his/her user_id (100 in above example) from PhoneBook table then i need to check if anyone from user_id = 100 phonebook's exist on Table Registered_User and if yes then returns all of Registered_User table column
Here is my query
SELECT * FROM Registered_User as MA
Join PhoneBook as N ON N.mobile Like '%' MA.Phone
where N.user_id = 100
Table Schema
CREATE TABLE `Phonebook` (
`id` int NOT NULL AUTO_INCREMENT,
`user_id` int NOT NULL,
`first_name` varchar(250) NOT NULL,
`mobile` varchar(250) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3520 DEFAULT CHARSET=latin1
The query above returns zero result even when the user 100(user id) has few users in Registered_User table. Can you help me to fix this query. I am not expert in creating query.
Table data should return result Tom 981000001 and Ron 981000002. Please let me know if i missed something and is this the best way to get the get the existing users of the app?
source https://stackoverflow.com/questions/73916817/mysql-using-like-to-match-phone-number
No comments:
Post a Comment