HOME       >>       Programming

Mysql Multiple Tables


darkken

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

$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.
$sql = "SELECT row FROM table WHERE row=1";
Now lets start into where we reference two tables in one query.
$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.

darasen

I confess I did not read the entire post though it is short as there are a few glaring errors near the beginning.

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.

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

$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.

=
$sql = "SELECT row FROM table WHERE row=1";

Is only going to select the information in one field of one row.

iGuest

MYSQL and PHP in nested queriesqMysql Multiple Tables

I got this query to run in mysql. And the same I need to run in php so that I can retrieve data and display it accordingly.Select tlc, fname" ",lname, points from user, history where user.TLC = history.Tlc group by fname;In mysql, it works perfrctly,But I am having great problems in php, and how to display it.Appreciate any help.

-reply by Ashneel

 


iGuest

PHP Script to print out all the data in each of the tablesMysql Multiple TablesHow do I write a PHP script that prints out all the data in each of the tables in my MySQL database...I really don't know where to start! Please help!-reply by Lynn

iGuest

sql to phpMysql Multiple Tables

I have run dis code in mysql and it executes fine.But how do I enter it into the php code such that it works fine and give me the exact results same as it gave in mysqlBelow is the MySQL code:Truncate transport_rate;Insert transport_rate(trans_id,rate)Select trans_id,"xx1111"From transport;Update transport_rateSet rate=(SELECT rate_9tonnerFROM transportWhere trans_id = transport_rate.Trans_id);Select transport.Trans_name,transport_rate.RateFrom transport join transport_rateUsing(trans_id);

-reply by Ashish Panda



VIEW DESKTOP VERSION REGISTERGET FREE HOSTING

Xisto.com offers Free Web Hosting to its Members for their participation in this Community. We moderate all content posted here but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2001-2019 by Xisto Corporation. All Rights Reserved.