Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Mysql Multiple Tables
darkken
post Jul 31 2008, 06:51 PM
Post #1


Newbie [ Level 2 ]
Group Icon

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.
Go to the top of the page
 
+Quote Post
Darasen
post Jul 31 2008, 08:35 PM
Post #2


Advanced Member
Group Icon

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.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. MySQL - Trouble With Bulk Insert Statements(3)
  2. MySQL Realtime Replication(4)
  3. Recover Tables From A MySQL .frm File(8)
  4. Mirror My MySQL Database To Another Mysql Server(4)
  5. How To Connect MySQL With Flash?(8)
  6. MySQL Output Database Question(18)
  7. MySQL, Multiple Tables(24)
  8. Linking Two Tables(12)
  9. Navcat For MySQL(9)
  10. Permission Problem With Mysql Database Creation(8)
  11. Mysql And Php(15)
  12. Login System Using A Mysql Db(5)
  13. Oracle Vs. Mysql Vs. Postgresql(9)
  14. Subqueries In Mysql(1)
  15. Apache Php With Mysql On Windows [solved](9)
  1. Not Understanding Mysql(4)
  2. Mysql - So Hard(14)
  3. Mysql Problem(1)
  4. Sun Bought Mysql(6)
  5. Mysql Backup With Another Address?(4)
  6. I Have An Error With My Mysql Connection(7)
  7. Mysql And User File_priv(0)
  8. Mysql Database Management(1)
  9. Mysql Database Entry By Excel Sheets(2)
  10. Mysql On Computer(9)
  11. Any Website Provide Free Host Mysql Host?(4)
  12. Mysql Overhead(3)
  13. Login System(6)


 



- Lo-Fi Version Time is now: 5th December 2008 - 01:19 AM