Unix Technical Forum

Confused on Query's

This is a discussion on Confused on Query's within the MySQL General forum forums, part of the MySQL category; --> lets say u have a table called Parts and another called Projects ,,, how can u associate the Parts ...


Go Back   Unix Technical Forum > Database Server Software > MySQL > MySQL General forum

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 06:59 AM
Brian E Boothe
 
Posts: n/a
Default Confused on Query's

lets say u have a table called Parts and another called Projects ,,,
how can u associate the Parts Table with the Projects table so lets say
u wanna add a Specific Part to a project maybe even add three parts
from the parts table and associate it with a specific project ???

so maybe u would have projectid = partsid ?

so your project id lets say would be 1222007BB but u wanna add 7
parts associated with that Projectid

hmm maybe whatever partnumber u add would be associated with the
projectid ???

such as Partnum = projectid ?? with a left join ?

can someone Give me an example of how i would do this ? thanks
alot


i wanna run a query and see the parts associated with each project !
thats my ultimate goal ,,




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 06:59 AM
Brent Baisley
 
Posts: n/a
Default Re: Confused on Query's

I assume each part can be associated with multiple projects, which is
a many to many relation. In that case you need to create a "join"
table that holds the relation. Table like that are typically just 2
fields, one for the project id and one for the part id. You may want
to add other fields like a timestamp so you know when the part was
added to the project.

Your query on the three tables (projects, projparts, parts) would
look something like this:
SELECT projects.*, parts.* FROM projects
JOIN projparts ON projects.projectid=projparts.projectid
JOIN parts ON projparts.partsid=parts.partsid
WHERE projects.projectid="1222007BB"

You would change those to left joins if you are not sure whether a
project has any parts. If there are no parts, that query would not
return anything.

On Aug 22, 2007, at 5:05 PM, Brian E Boothe wrote:

> lets say u have a table called Parts and another called
> Projects ,,, how can u associate the Parts Table with the Projects
> table so lets say u wanna add a Specific Part to a project maybe
> even add three parts from the parts table and associate it with a
> specific project ???
>
> so maybe u would have projectid = partsid ?
>
> so your project id lets say would be 1222007BB but u wanna add 7
> parts associated with that Projectid
>
> hmm maybe whatever partnumber u add would be associated with the
> projectid ???
>
> such as Partnum = projectid ?? with a left join ?
>
> can someone Give me an example of how i would do this ?
> thanks alot
>
>
> i wanna run a query and see the parts associated with each
> project ! thats my ultimate goal ,,
>
>
>
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?
> unsub=brenttech@gmail.com
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:33 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com