MySQL is a highly popular relational database in today’s programming world. With features that allow for table-to-table relationships, MySQL databases have become the most widely used databases worldwide. Before delving deeper, for those of you who haven’t read the previous article, please read Web Programming and Mobile Devices – Library Part-1 as this article is related to the previous one.
To combine data between tables, a relationship between one table and another is necessary. In Database learning, this action is referred to as table relationships. This involves linking between tables. For a clearer understanding, let’s directly practice by following the steps I’ve prepared below.
Before proceeding, make sure you have followed the previous tutorial, as this time we will continue the discussion and add a new table to the same database.
Table Relationship in Database Using Join Operation and Classic Model
1. Create a new table named “member” with its fields as shown in the following image.
2. Next, create a new table named “user” with fields according to the following image.
Observe the two newly created tables. Both of these tables have fields as connectors between the two tables that I’ve prepared. The connector in the “member” table is useradd, while in the “user” table it’s id_user.
Now, let’s establish a relationship between these two tables.
3. Creating Classic Model Relationship Query
The following query is used to display member data along with the name of the Admin who inputted the data. Please execute the following query to see the results:
1 |
SELECT a.*, b.`nm_user` AS input_admin FROM member a, `user` b WHERE a.`useradd` = b.`id_user` |
4. Creating Relationship Query Using Inner Join
With the same function as the classic query above, please execute the following query:
1 |
SELECT a.*, b.`nm_user` FROM member a INNER JOIN `user` b ON a.`useradd` = b.`id_user` |
Both of the above operations serve the same purpose: to combine and display data from two related tables. The difference is that the classic operation is simpler but is only recommended for table relationships with a small amount of data. Using the classic model operation with large tables will be very slow. On the other hand, the join-based relationship operation is a bit more complex, but highly effective in handling large amounts of data.
Feel free to practice to experience the difference. If you have any questions about this topic, please leave a comment in the comment section below this article. Hope it’s helpful…
terima kasih sangat bermanfaat 🙂 walau pun ga paham tetap berguna !
terima kasih sangat bermanfaat 🙂 walau pun ga paham tetap berguna !
Sangat bermanfaat sekali…
Terimaksh sdah berkunjung…