O
O
ortsuev332018-11-21 15:25:49
SQL
ortsuev33, 2018-11-21 15:25:49

How to make a request correctly or what alternative can be done in php?

The task is such that I have cities in a table with id, I received several ids and I need to get them all, I see two options here through in or make several queries through a loop or a function call. In in when two identical ids come to me, only one city for two id will be returned to me, in the second case, it’s probably not reasonable to make a query to the database every time, tell me what to do, it’s not necessary to change the logic in sql, you can also in php

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
ortsuev33, 2018-11-22
@ortsuev33

Solved the problem with inner join

J
Just A Bit, 2018-11-21
@justabit

In in when two identical ids come to me, only one city for two id will be returned to me

You have a bit of a logic problem here. If we tell you through PHP a request for one city ID came 5 times, then you make a request 1 time, and then through PHP process the response from the DB and display this city 5 times.

X
xmoonlight, 2018-11-21
@xmoonlight

(something like that, but not tested...)

SELECT *
FROM `table`
WHERE EXISTS(select 1 from `table` WHERE id IN (1,1,3,1,5))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question