Webspace hosting - Introducing MySQL SQL 57 address2 varchar(64), address3 varchar(64),
Introducing MySQL SQL 57 address2 varchar(64), address3 varchar(64), city varchar(64), state varchar(64), zip varchar(10), ts timestamp not NULL, act_ts timestamp, primary key(add_id, ts)); Query OK, 0 rows affected (0.00 sec) Let s now add some data to the table for the account ID 1034055. Notice that the acc_add table requires the acc_id of the account whose address is being added to the table. This column value links the acc table with the acc_add table. The full data added to the table can be found on the code download available at www.wiley.com/compbooks/matthews. In this example, we ve added two rows: mysql> insert into acc_add values(30004, 1034055, ‘John Doe’, ‘4565 Some St’, ‘Suite 4′, NULL,’Chicago’, ‘IL’, ‘21734′, 0, now()); Query OK, 1 row affected (0.00 sec) mysql> insert into acc_add values( 30003, 1034055, ‘John Doe’, ‘123 Any St’, NULL, NULL,’Atlanta’, ‘GA’, ‘38394′, 0, now()); Query OK, 1 row affected (0.00 sec) Now we want to get data from both tables at the same time. For example: mysql> SELECT acc.acc_id, name FROM acc, acc_add WHERE acc.acc_id = acc_add.acc_id and acc.ts = 0; +———+———-+ | acc_id | name | +———+———-+ | 1034055 | John Doe | | 1034055 | John Doe | +———+———-+ 2 rows in set (0.00 sec) In this query, we asked for the values of acc_id (from the acc table) and name (from the acc_add table), but only when the acc_id in both of the tables match and the ts field in the acc table is 0. The result is two rows. Let s look a little more closely at what is occurring in this SQL. First, we are asking for data from two tables at the same time, as seen in the FROM acc, acc_add clause. From those two tables, we want two pieces of data: the acc_id and name. Notice how the acc_id has a table name preceding it. This had to be done in order to tell the database server which table we want the acc_id to be pulled from because it can be found in both of them. Now we want to see data from the tables only when the acc_id is identical between the two tables. At this time, the only data in the acc_add table has an
Hint: This post is supported by Gama php5 hosting services