W
W
w_b_x2016-03-01 19:32:09
PHP
w_b_x, 2016-03-01 19:32:09

How to select from array in MYSQL?

Good day, thanks for clicking on this question!
And so, the question is this, dear reader:
I made a selection from the MYSQL table using PHP, conditionally like this:

id1 = mysql_query("SELECT `id` FROM `users` WHERE `balance` > 2");

And I got an array of previously suitable IDs, I have a second table and I need to remove from the current array all IDs that are not in the second table (so to speak, make a comparison), purely on the fingers, something like:
mysql_query("SELECT * FROM `table2` WHERE `id2` = `id1`)

How is this done?
I already thought it was a sinful thing to make a cycle in PHP with the help of which a bunch of SQL queries make a selection, but this is barbarism.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
neco_boy, 2020-01-03
@neco_boy

In this case, a nested selection like SELECT * FROM table1 WHERE id IN (SELECT id FROM table2) will help; there are plenty of examples on the internet.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question