OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
Re: Question about reading info from another table.

From: Rob Wultsch (wultschgmail.com)
Date: Thu Feb 28 2008 - 13:31:51 CST


I was referering to what you sent into the mysql user list.
Descriptive table/columns are ideal in production. When asking for
assistance it is ideal to remove extraneous detail.

On Thu, Feb 28, 2008 at 12:18 PM, Jason Pruim <japruimraoset.com> wrote:
>
> On Feb 28, 2008, at 2:06 PM, Rob Wultsch wrote:
>
> > What you are probably wanting is a join, but how does adminAll relate
> > to current?
>
> adminAll will be for the administrators of my program to log into so
> instead of getting redirected automatically to a certain table
> (current.tableName in this case) they get a list of available tables
> in the database (adminAll.displayTableName) so that I don't have to
> have a separate admin login for each database I setup with my program.
>
>
>
> > Generally it is a good idea to have the column that
> > relates the tables (read http://en.wikipedia.org/wiki/Foreign_key if
> > you want to work at a much high level ) have the same column name if
> > possible (IMHO).
>
> the column name won't be an issue since I'm writing it all from
> scratch :) making it the same name to help improve readability between
> the tables in the database I'm assuming?
>
>
>
> > In the example I sent I had a column in both tables
> > name t2_id. Take a look at http://www.w3schools.com/sql/sql_join.asp
> > for simple joins. The syntax in the first couple examples (without
> > using JOIN) is a good idea to avoid (also IMHO) .
>
> I will look at those as soon as I'm done sending this e-mail! Thank you
>
>
> >
> >
> > The new table you sent is good, but it is more ideal to remove
> > unnecessary columns and make the table /column names generic.
>
> Can I ask why? So far, everything I have done with MySQL would seem to
> suggest setting column names so it makes sense what info is stored in
> it? (IE: First Name would go into FName or firstname or namefirst or
> something like that)
>
>
>
>
> >
> >
> > On Thu, Feb 28, 2008 at 11:49 AM, Jason Pruim <japruimraoset.com>
> > wrote:
> >>
> >>
> >> On Feb 28, 2008, at 1:29 PM, Rob Wultsch wrote:
> >>
> >>> On Thu, Feb 28, 2008 at 10:59 AM, Jason Pruim <japruimraoset.com>
> >>> 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
> >>>> japruimraoset.com
> >>>
> >>> 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.
> >>
> >> Hi Rob, I will do this in the future, thank you.
> >>
> >> And to that end:
> >>
> >> CREATE TABLE `current` (
> >> `customerName` varchar(30) default NULL,
> >> `customerBusiness` varchar(30) default NULL,
> >> `loginName` varchar(30) default NULL,
> >> `loginPassword` varchar(32) default NULL,
> >> `tableName` varchar(20) default NULL,
> >> `email` varchar(50) default NULL
> >> ) ENGINE=MyISAM DEFAULT CHARSET=latin1
> >>
> >>
> >> CREATE TABLE `adminAll` (
> >> `dispalyTableName` varchar(20) default NULL,
> >> `adminLevel` int(10) default NULL,
> >> `date` timestamp NOT NULL default CURRENT_TIMESTAMP on update
> >> CURRENT_TIMESTAMP
> >> ) ENGINE=MyISAM DEFAULT CHARSET=latin1
> >>
> >>
> >> What I want, is displayTableName on table adminAll to grab it's info
> >> from tableName in current. Does that make more sense?
> >>
> >>
> >>
> >>>
> >>>
> >>> 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)
> >>
> >> I have been working with MySQL in various degrees for the past few
> >> years, I've just never needed to grab info from another table and
> >> import it to a different table.
> >>
> >> My Main area of expertise is in web design (mostly HTML and CSS) and
> >> some PHP.
> >>
> >>>
> >>>
> >>> From the above question you probably do not know enough to tread
> >>> water
> >>> in the very excellent MySQL manual.
> >>>
> >>
> >>
> >> From my original post:
> >>
> >>
> >>>> "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 :)"
> >>> --
> >>> Rob Wultsch
> >>
> >>
> >>>
> >>
> >> --
> >>
> >> Jason Pruim
> >> Raoset Inc.
> >> Technology Manager
> >> MQC Specialist
> >> 3251 132nd ave
> >> Holland, MI, 49424-9337
> >> www.raoset.com
> >> japruimraoset.com
> >>
> >>
> >>
> >>
> >
> >
> >
> > --
> > Rob Wultsch
> > (480)223-2566
> > wultschgmail.com (email/google im)
> > wultsch (aim)
> > wultschhotmail.com (msn)
> >
>
> --
>
> Jason Pruim
> Raoset Inc.
> Technology Manager
> MQC Specialist
> 3251 132nd ave
> Holland, MI, 49424-9337
> www.raoset.com
> japruimraoset.com
>
>
>
>

--
Rob Wultsch
(480)223-2566
wultschgmail.com (email/google im)
wultsch (aim)
wultschhotmail.com (msn)

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql