Question: mysql Subqueries
If I run this query:
SELECT `Manga`.`id`, `Manga`.`name` FROM `mangas` AS `Manga` WHERE `Manga`.`id` in
(
SELECT `manga_id` FROM `mangas_genres` wher开发者_高级运维e `manga_id` = 1
)
My computer does not respond (I just mistype). It can't run this query. Is the above code invalid? Please, help me.
I think it is valid, but it can't run. I don't understand. It sure be MySQL, I run query on MYSQL workbench (not in PHP) my computer be very slower ( while run query) My table mangas and mangas_genres have more than 5000 rows.
That's a valid query, assuming that all table and column names are spelled correctly.
CREATE TABLE mangas_genres (manga_id INT NOT NULL); INSERT INTO mangas_genres (manga_id) VALUES (1); CREATE TABLE mangas (id INT NOT NULL, name VARCHAR(100) NOT NULL); INSERT INTO mangas (id, name) VALUES (1, 'manga1'), (2, 'manga2'); SELECT `Manga`.`id`, `Manga`.`name` FROM `mangas` AS `Manga` WHERE `Manga`.`id` in ( SELECT `manga_id` FROM `mangas_genres` where `manga_id` = 1 )
Result:
id name 1 manga1
Your problem is somewhere else.
My query is valid but lost many time to run query (>100s on my computer , it cause computer to very slower (not responding)), The solve is index to speed up
精彩评论