简体   繁体   中英

MySQL queries: two SELECT or one with LEFT Join?

Is there any difference between two SELECTs from database or single SELECT with LEFT Join ?

I am limited by number of queries per hour and I am developing my own application.

"SELECT * FROM table" represents one query?

"SELECT * FROM table LEFT JOIN another_table ON table.column=another_table.column2'" represents one query too?

Are UPDATE , INSERT and DELETE considered query?

Thanks a lot. If my post is not ok, I can delete.

If you have limited number of queries, than LEFT JOIN is better, since it's only one query (one connection to database). And yes, UPDATE , INSERT , DELETE is queries too. But You can insert multiple entries with single query.

Yes, joining tables is one query. Splitting that query and executing separately will take more time.

LEFT JOIN is better, because it is only one query and need only one connection to database.

SELECT , UPDATE , DELETE and INSERT are all queries

It's almost always better to use less query than more, so in your case better to use join than run 2 queries.

However you should add indexes to table.column and another_table.column2 to make sure it won't affect your performance.

Of course all queries, also UPDATE , DELETE and INSERT are considered as queries, not only SELECT

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM