How to make a subquery to SELECT?

Good time of day.
There is a table `users` with users, there are such columns as `user_id` and `ip`.
You first have to take all znachenia `ip` from a specific user, and then to select the results to the entire table.
SELECT * FROM `users`
WHERE `ip` = (select `ip` FROM `users_base` WHERE `user_id` = 'blahblahblah');

This request hangs.
Tried
create table `user_tmp` (ip VARCHAR(32));
insert INTO `user_tmp` (select `ip` from `users` WHERE `user_id` = 'blahblahblah');
select * from `users` WHERE `ip` IN (select `ip` FROM `user_tmp');

Complains for a syntax error.
July 12th 19 at 17:18
3 answers
July 12th 19 at 17:20
Solution
SELECT * FROM `users`
WHERE `ip` IN (select `ip` FROM `users_base` WHERE `user_id` = 'blahblahblah');


create table `user_tmp` (ip VARCHAR(32));
insert INTO `user_tmp` (select `ip` from `users` WHERE `user_id` = 'blahblahblah');
select * from `users` WHERE `ip` IN (select `ip` FROM `user_tmp`);
Thank you, the quote really came bobble. But the first option exceeds the timeout in 600 seconds. - Darrel79 commented on July 12th 19 at 17:23
: well, it's just a bad query. Decides EXISTS in this case... - Zachary_Botsford40 commented on July 12th 19 at 17:26
July 12th 19 at 17:22
Solution
SELECT `u2`.*
 FROM `users` AS `u1`
 JOIN `users` AS `u2` ON `u1`.`user_id` = :user_id AND `u2`.`ip` = `u1`.`ip`
Swears on syntax. - Darrel79 commented on July 12th 19 at 17:25
And you parameter :user_id replaced by the desired data? - Zachary_Botsford40 commented on July 12th 19 at 17:28
Yes, but again messed up novichkam, my curse. And the query works fine, thank you very much. - Darrel79 commented on July 12th 19 at 17:31
July 12th 19 at 17:24
If the number of IP for one user does not exceed ~1000 - the fastest option will be 2 request
1)
select `ip` FROM `users_base` WHERE `user_id` = 'blahblahblah'


2)
SELECT * FROM `users`
WHERE `ip` IN ( ... )
instead ... write a specific ip address obtained from the last request.

Find more questions by tags MySQL