Discussion: Confused on Query's
Afficher un message
Vieux 23/08/2007, 01h18   #2
Brent Baisley
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
>


  Réponse avec citation
 
Page generated in 0,05064 seconds with 9 queries