On Thu, Feb 28, 2008 at 10:59 AM, Jason Pruim <[EMAIL PROTECTED]> wrote:
> Hi Everyone,
>
>  I am attempting to write a PHP application that reads info from a
>  MySQL database, and I'm wondering if I can set up a column in one
>  table that gets it's info from a field in another table automatically?
>  Ie:
>
>  Table1:
>  field1
>  field2
>  field3
>
>  Table2:
>  field4
>  field5
>  field6 = field1
>
>  Does that make sense? Would that be a join? Or maybe a primary key?
>  I'm new to MySQL programming so RTFM's are appreciated as long as "M"
>  is defined :)
>
>
>  --
>
>  Jason Pruim
>  Raoset Inc.
>  Technology Manager
>  MQC Specialist
>  3251 132nd ave
>  Holland, MI, 49424-9337
>  www.raoset.com
>  [EMAIL PROTECTED]

Tip for future questions:
Figure out the simplest way to present the question and include the
SQL to create the relevant tables.
Next explain what you want, any non working sql you have, and lastly
give an example result of correct output.

Example:
So lets say I have two tables:
CREATE TABLE `t1` (
  `t1_id` int(10) NOT NULL auto_increment,
  `t1_data` varchar(255) NOT NULL default '',
  `t2_id` int(10) NOT NULL default '0',
  PRIMARY KEY  (`t1_id`),
  KEY `t2_id` (`t2_id`)
);

CREATE TABLE `t2` (
  `t2_id` int(10) NOT NULL auto_increment,
  `t2_data` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`t2_id`)
);

I want to show all the information in t1 and any information in t2
where the t1.t2_id is equal to t2.t2_id.
Output should be like:
t1_id,
t1_data,
t2_data

*Answer*
I really am not sure what you were asking, but take a look at this
query for the table structure above.
SELECT t1_id, t1_data, t2_data
FROM t1
INNER JOIN t2 USING(t2_id)

*Better answer*
Go buy an introductory book on sql.  Read through a couple examples.
( http://www.w3schools.com/sql/default.asp is also very good)

>From the above question you probably do not know enough to tread water
in the very excellent MySQL manual.

-- 
Rob Wultsch

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to