A
A
Albert Kazan2018-04-13 11:06:08
MySQL
Albert Kazan, 2018-04-13 11:06:08

How to write a sample?

While I'm making a selection like this

SELECT id, worker_id, (SELECT name FROM people WHERE id=worker_id) AS worker_name, (SELECT login FROM people WHERE id=worker_id) AS worker_login FROM workers_ads

The page is rendered in ~0.09 seconds. I think the reason for the slowdown in this "stupid" sample. What would be the best way to choose everything?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Leonid Rozhnov, 2018-04-13
@Farrien

Well, at least like this:

SELECT id, worker_id, p.name AS worker_name, p.login AS worker_login FROM workers_ads wa
join people p on p.id = wa.worker_id

As for the rest, you should already look in the database to see if there are the necessary indexes there, what size of the table, etc.
And you should still read some smart book on SQL, the question is very basic.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question