|
|
|
|
![]() ![]() |
Jul 31 2008, 06:51 PM
Post
#1
|
|
|
Newbie [ Level 2 ] Group: [HOSTED] Posts: 26 Joined: 2-July 08 Member No.: 31,263 |
It is good practice to use multiple tables to sort out big amounts of data. But once you do that it becomes increasingly hard to cross reference the tables. Mysql has a little beautiful command structure that they have added. You can select multiple tables within one sql query. Example of a basic sql query
CODE $sql = "SELECT * FROM table WHERE row=1"; If you noticed that I selected all of the rows in the table. Normally you will try to not select the entire table from the database unless you absolutely want all of the table. I would recommend against it; just grab the tables that you really need. CODE $sql = "SELECT row FROM table WHERE row=1"; Now lets start into where we reference two tables in one query. CODE $sql = "SELECT t1.username t2.email FROM t1.users, t2.profile WHERE username LIKE CONVERT( _utf8 'bob' USING latin1 )"; And presto you have multiple table query. You can also use this to delete tables too but I would recommend that you copy the table before running the command because you might not get the result you are looking for. Keep in mind if you do copy the table, it isn't very efficient to copy tables if the tables are huge. You might want to then just take a few tables and put them into a table and then run the command and then see the result because if you are using 4 gb databases you don't want to copy the whole database into another just to see if the command works. |
|
|
|
Jul 31 2008, 08:35 PM
Post
#2
|
|
|
Advanced Member Group: [HOSTED] Posts: 185 Joined: 3-April 08 From: Milling about Member No.: 29,596 myCENTs:2.81 |
I confess I did not read the entire post though it is short as there are a few glaring errors near the beginning.
QUOTE It is good practice to use multiple tables to sort out big amounts of data. But once you do that it becomes increasingly hard to cross reference the tables. Multiple tables are to sort different data and avoid repetition of data. If using multiple tables makes the Data harder to understand then the data model is not good at all and the database in question needs to be redesigned. QUOTE Mysql has a little beautiful command structure that they have added. You can select multiple tables within one sql query. Example of a basic sql query ANSI (the standard) SQL allows the use of multiple tables. That is what the JOINs are for QUOTE CODE $sql = "SELECT * FROM table WHERE row=1"; If you noticed that I selected all of the rows in the table. Normally you will try to not select the entire table from the database unless you absolutely want all of the table. I would recommend against it; just grab the tables that you really need. Correction, this statement selects all the columns from a single row as written. Looking at the the statement SELECT starts the SQL command to select certain items from the database. After the select we tell the interpreter what exactly it is we wish to select starting with what columns (or fields if you will) of data we need. Using the asterisk will select all of the columns from the table not all of the rows. The WHERE statement is telling the DB to just pull row 1. Given the statement we have to assume that that row is a column name. Of course ROW is a reserved word in the SQL standard. = CODE $sql = "SELECT row FROM table WHERE row=1"; Is only going to select the information in one field of one row. |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 5th December 2008 - 01:19 AM |