e80db317179e4652a391c28d429643d9
mysql MySQL Tutorial: Displaying Data from Multiple TablesIn previous articles I’ve discussed about MySQL but are implemented in php code. for those who have not read it please read here “Tutorial a Drop Down List Box Using PHP & MYSQL“. in this article I will only discuss about the MySQL course. ie about “MySQL Tutorial: Displaying Data from Multiple Tables“. Let’s continue this article. to the point. In a RDBMS including MySQL, of course, already become a fairness if in a single database can consist of several tables. Each table can be related (correlated) with each other. Relationships between tables can be a relationship one-to-one, one-to-many, or many-to-many.

In making an application, sometimes we also need a data view that is not only derived from (one) table, but could be from several tables at once.

ine (two) or more tables, we can use the JOIN command. In this tutorial, will explain step by step on how to merge two tables or more, primarily to display data from several tables. The examples in this tutorial has been tested specifically in the MySQL database, however the general command of all types of merging database tables are not much different from the same alias.

Inner Join
With inner join, the table will be incorporated in both directions, so there is no NULL data on one side.

1. Inner Join with WHERE.

Merging with a WHERE clause has the general form as follows:

SELECT tabel1.*, tabel2.* FROM tabel1, tabel2
WHERE tabel1.PK=tabel2.FK;

I think you already know what the mean PK and FK icon wink MySQL Tutorial: Displaying Data from Multiple Tables
PK= Primary Key
FK= Foreign Key

2. Inner Join with INNER JOIN clause.

Following general form:

SELECT tabel1.*, tabel2.*
FROM tabel1 INNER JOIN tabel2
ON tabel1.PK=tabel2.FK;

Outer Join
With an outer join, the table will be merged in one direction, so no data which allows NULL (empty) on one side.
Outer Join divided into 2 (two), namely LEFT JOIN and RIGHT JOIN. Following general form:

1. LEFT JOIN.

General form:

SELECT tabel1.*, tabel2.*
FROM tabel1 LEFT JOIN tabel2
ON tabel1.PK=tabel2.FK;

1. Right JOIN.

General form:

SELECT tabel1.*, tabel2.*
FROM tabel1 RIGHT JOIN tabel2
ON tabel1.PK=tabel2.FK;

Combining three Tables or More

To combine the three tables or more, basically the same as the merger of two (two) tables.
How SQL commands it? Who can? or anyone would try to implement it in PHP code? please answer in the comments section below this tutorial.

GHTime Code(s): nc e9a14 

Incoming search terms for the article:

Related Post:

Tagged with:

Filed under: MySQL

Like this post? Subscribe to my RSS feed and get loads more!