Unix Technical Forum

should I use join?

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 ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 09:35 AM
mcardeiro@yahoo.com
 
Posts: n/a
Default should I use join?

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 09:35 AM
Sanders Kaufman
 
Posts: n/a
Default Re: should I use join?

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 09:35 AM
Jerry Stuckle
 
Posts: n/a
Default Re: should I use join?

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
==================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 09:36 AM
Sanders Kaufman
 
Posts: n/a
Default Re: should I use join?

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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 09:36 AM
Jerry Stuckle
 
Posts: n/a
Default Re: should I use join?

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
==================
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 04:11 PM.


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