This is a discussion on should I use join? within the MySQL forums, part of the Database Server Software category; --> Hi I am stumped on a select statement. basically I have 2 tables I want to use in my ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi I am stumped on a select statement. basically I have 2 tables I want to use in my select table1 = "uploads" has fields 'id', 'size' table 2 = "uploadOwners" has field 'id' which is a foreign key referencing uploads.id, and field 'owner' "uploads" +-----+------------+ | id | size | +-----+------------+ | 1 | 653636 | | 2 | 45674 | | 3 | 5678 | +-----+------------+ "uploadsOwners" +-----+------------+ | id | owner | +-----+------------+ | 1 | bill | | 2 | john | | 3 | john | +-----+------------+ basically, I only want to select entries from "uploads" that are referenced to uploadOwners.owner="john" I am at a loss for the proper syntax Mike Cardeiro |
| |||
| mcardeiro@yahoo.com wrote: > Hi > > I am stumped on a select statement. basically I have 2 tables I want > to use in my select > > table1 = "uploads" has fields 'id', 'size' > > table 2 = "uploadOwners" has field 'id' which is a foreign key > referencing uploads.id, and field 'owner' > > "uploads" > +-----+------------+ > | id | size | > +-----+------------+ > | 1 | 653636 | > | 2 | 45674 | > | 3 | 5678 | > +-----+------------+ > > > "uploadsOwners" > +-----+------------+ > | id | owner | > +-----+------------+ > | 1 | bill | > | 2 | john | > | 3 | john | > +-----+------------+ > > basically, I only want to select entries from "uploads" that are > referenced to uploadOwners.owner="john" You might not want a join per se (that requires some ForeignKey Kung-fu) - but rather a compound select. |
| |||
| mcardeiro@yahoo.com wrote: > Hi > > I am stumped on a select statement. basically I have 2 tables I want > to use in my select > > table1 = "uploads" has fields 'id', 'size' > > table 2 = "uploadOwners" has field 'id' which is a foreign key > referencing uploads.id, and field 'owner' > > "uploads" > +-----+------------+ > | id | size | > +-----+------------+ > | 1 | 653636 | > | 2 | 45674 | > | 3 | 5678 | > +-----+------------+ > > > "uploadsOwners" > +-----+------------+ > | id | owner | > +-----+------------+ > | 1 | bill | > | 2 | john | > | 3 | john | > +-----+------------+ > > basically, I only want to select entries from "uploads" that are > referenced to uploadOwners.owner="john" > > I am at a loss for the proper syntax > > > > Mike Cardeiro > How about something like: SELECT * FROM uploads JOIN uploadsOwners ON uploads.id = uploadsOwners.id WHERE uploadsOwners.owner = 'john'; -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
| ||||
| Sanders Kaufman wrote: > Jerry Stuckle wrote: > >> How about something like: >> >> SELECT * FROM uploads >> JOIN uploadsOwners ON uploads.id = uploadsOwners.id >> WHERE uploadsOwners.owner = 'john'; > > > Does that require Foreign Key relationship? No, joins do not require a foreign key relationship. Foreign keys are strictly for DELETE statements or UPDATE statements where the key is being changed. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |