Hi I am not understanding , why the subquery of given query is converting into dependent subquery.

Although the subquery is not dependent(not using primary query table) on main query.

I know that this query can be optimized using joins,but here i just want to know the reason of this

EXPLAIN SELECT id  FROM  `cab_request_histories` 
WHERE cab_request_histories.id = any(SELECT id
                                     FROM cab_requests
                                     WHERE cab_requests.request_type =  'pickup')

id   select_type      table type           possible_keys     key               key_len  ref rows Extra
1    PRIMARY    cab_request_histories   index             NULL             PRIMARY  4   NULL    20                       

2    DEPENDENT       SUBQUERY          cab_requests unique_subquery    PRIMARY  PRIMARY 4 func  1
Member Avatar for LastMitch

I know that this query can be optimized using joins,but here i just want to know the reason of this

Are you asking for a opinion or a suggestion or an answer?

Did you write this query or you find it online?

The way you post this question it seems you are not sure how this works and my impression is that you didn't write this query and I don't know what you are trying to do or get out of this?

You can read this it will explain subqueries and joins in mysql (How to optimize subqueries and joins in MySQL):

http://www.xaprb.com/blog/2006/04/30/how-to-optimize-subqueries-and-joins-in-mysql/

You can also read this it will give you tips & techniques on optimize subqueries (Optimization Tips & Techniques):

http://sqlserverpedia.com/wiki/Optimization_Tips_%26_Techniques

Thanks @LastMitch The links were helpful.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.