Unix Technical Forum

Newbie - Easy (I think) SQL Syntax Question, 3 table join

This is a discussion on Newbie - Easy (I think) SQL Syntax Question, 3 table join within the Informix forums, part of the Database Server Software category; --> I have three identical tables, t1, t2, t3 Each table contains a complete list of files on a particular ...


Go Back   Unix Technical Forum > Database Server Software > Informix

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 07:08 PM
John Walsh
 
Posts: n/a
Default Newbie - Easy (I think) SQL Syntax Question, 3 table join

I have three identical tables, t1, t2, t3

Each table contains a complete list of files on a particular server.

One of the fields in each table is owner (the owner of an individual
file)

What is the SQL syntax to get a list of all the files owned by a
single user "abcde" from the three tables ?

I can do this in three statements:

Select * from t1 where t1.owner = "abcde";
Select * from t2 where t2.owner = "abcde";
Select * from t3 where t3.owner = "abcde";

The question is how can I do this in one statement?

Here is my first attempt:

Select * from t1,t2,t3
where t1.owner = "abcde"
and t1.owner = t2.owner
and t2.owner = t3.owner

This fails to give the correct answer.

select * from (t1 INNER JOIN t2 on t1.owner = t2.owner) INNER JOIN t3
on t3.owner = t1.owner

This also fails to give the correct answer.

Thanks,

John
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-19-2008, 07:08 PM
Michael Krzepkowski
 
Posts: n/a
Default Re: Newbie - Easy (I think) SQL Syntax Question, 3 table join

John Walsh wrote:

>I have three identical tables, t1, t2, t3
>
>Each table contains a complete list of files on a particular server.
>
>One of the fields in each table is owner (the owner of an individual
>file)
>
>What is the SQL syntax to get a list of all the files owned by a
>single user "abcde" from the three tables ?
>
>I can do this in three statements:
>
>Select * from t1 where t1.owner = "abcde";
>Select * from t2 where t2.owner = "abcde";
>Select * from t3 where t3.owner = "abcde";
>
>

select * from t1 where t1.owner = "abcde"
union
select * from t2 where t2.owner = "abcde"
union
select * from t3 where t3.owner = "abcde";

HTH

Michael

>The question is how can I do this in one statement?
>
>Here is my first attempt:
>
>Select * from t1,t2,t3
>where t1.owner = "abcde"
>and t1.owner = t2.owner
>and t2.owner = t3.owner
>
>This fails to give the correct answer.
>
>select * from (t1 INNER JOIN t2 on t1.owner = t2.owner) INNER JOIN t3
>on t3.owner = t1.owner
>
>This also fails to give the correct answer.
>
>Thanks,
>
>John
>
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-19-2008, 07:08 PM
Art S. Kagel
 
Posts: n/a
Default Re: Newbie - Easy (I think) SQL Syntax Question, 3 table join

On Thu, 10 Jul 2003 18:30:32 -0400, John Walsh wrote:

select * from t1, t2, t3
where t1.owner = t2.owner
and t2.owner = t3.owner
and t3.owner = 'abcde'
and t1.filename = t2.filename
and t2.filename = t3.filename;

Art S. Kagel

> I have three identical tables, t1, t2, t3
>
> Each table contains a complete list of files on a particular server.
>
> One of the fields in each table is owner (the owner of an individual
> file)
>
> What is the SQL syntax to get a list of all the files owned by a single
> user "abcde" from the three tables ?
>
> I can do this in three statements:
>
> Select * from t1 where t1.owner = "abcde"; Select * from t2 where
> t2.owner = "abcde"; Select * from t3 where t3.owner = "abcde";
>
> The question is how can I do this in one statement?
>
> Here is my first attempt:
>
> Select * from t1,t2,t3
> where t1.owner = "abcde"
> and t1.owner = t2.owner
> and t2.owner = t3.owner
>
> This fails to give the correct answer.
>
> select * from (t1 INNER JOIN t2 on t1.owner = t2.owner) INNER JOIN t3 on
> t3.owner = t1.owner
>
> This also fails to give the correct answer.
>
> Thanks,
>
> John

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 09:29 AM.


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