473,405 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Advantages of JOIN

296 100+
Hello,

Does avoiding multiple queries the only advantage of JOIN ?
Jun 24 '08 #1
2 7598
Atli
5,058 Expert 4TB
Using JOINS, you can fetch exactly the data you want from any number of tables with just one query, using any search parameter you chose to filter the results. MySQL can also utilize things such as Indexes to maximize performance, which your API code can not.

Generally speaking, executing multiple queries and using some sort of API, such as PHP, to filter the results creates a lot more overhead for the servers. A lot more data has to be sent back and forth between MySQL and the API, not to mention that MySQL is built for optimal performance, which is in no way guaranteed when dealing with per-developer API code.
Jun 25 '08 #2
coolsti
310 100+
There is another advantage to the use of joins. By using joins instead of multiple queries, you maximize the placement of the calculation burden on the database. This means you can make better use of the database's abilities to search through, filter, sort, etc.

Here is an example: Let us say you wish to perform a search for data that is stored in several different tables. You can do this with one query using table joins, or perhaps in several queries, and then package the data for display afterwards with something like PHP. But let us say you wish to "paginate". That is, let us say you wish to not extract all the possible rows that match your select criteria, but only perhaps 25 rows at a time. And let us say you wish to extract the "third page" of this selection, in other words, rows 51 to 75. If you set this up to use only one query using table joins, you can easilly do this select using the limit clause "limit 51,25". This way you extract only the 25 rows that you want, no more.

If instead, you did this with multiple queries, you would have to in effect extract all the matching rows for all the queries, do whatever manipulations are needed in PHP arrays afterwards, and then throw everything away except for the 25 rows you wish to show. You cannot just use the "limit 51,25" clause on the individual queries, because the row locations of theindividual query results will in general not be the same.

In general, it is far best to put as much of the selection related computations to the database as possbile. However, should the resulting query become overly complicated resulting in excessive database computational effort (and adding a few indices will not help) then it is better to break it down and do the task in multiple queries.
Jun 27 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: bissatch | last post by:
Hi, Generally if I re-use code, I use a function. If I need to use these functions over a number of pages I write the function to an include file where all pages have access. So when should I...
6
by: D & J G | last post by:
Hi all I'm totally familiar with VB5 but am considering moving to VB6 soon. However, I am a little apprehensive as to what difficulties, if any, are ahead. To those that have progressed.....
65
by: Anthony_Barker | last post by:
I have been reading a book about the evolution of the Basic programming language. The author states that Basic - particularly Microsoft's version is full of compromises which crept in along the...
17
by: Kamil Burzynski | last post by:
Hello. I have to create short (1 hour) presentation about C++ advantages over C. Are there any good articles/texts/etc. about such topic? Personally, I'm quite proficient at C++ myself (e.g....
2
by: Mark | last post by:
Hi all, a quick ADO.NET question in regards to the command object. What are the advantages (if any) of specifying command parameters when executing a stored procedure over just calling the stored...
1
by: Husam | last post by:
Hi EveryBody: I have research about advantages and disadvantages of C++ languages In one of my programming courses. Can Any one help me and told me about advantages and disadvantages of C++...
1
by: vumani | last post by:
what is the advantages and disadvantages of Ms SQL server and java servletts front-end on the clien end. what is the advantages and disadvantages of Ms Access on the server, connected via JDBC and...
1
by: bantunks | last post by:
Hello, I am trying to figure out the advantages and disadvantages of exposing interfaces through Opaque data types in C. I have figured/found out the following two advantages 1. Higher level of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.