Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > Everything SQL ( MySQL, MSSQL, DB2, Postgre, Oracle, etc...)
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 05-30-2007, 05:43 PM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
clauses in a join

Code:
select a.field1 b.field2 from apples a left join bannanas b on b.field1=a.field1 and b.field3 > 0 and b.field4 = 2 where a.field2='foo'
can anyone explain what the code after the left join means? .. i understand b.field1=a.field1, .. but i came across some code today which has more conditions after the left join and before the where clause.
__________________
testing 1 2 3
sde is offline   Reply With Quote
Old 05-31-2007, 12:38 AM   #2 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 635
DJMaze is on a distinguished road
left join bannanas b on (b.field1=a.field1 and b.field3 > 0 and b.field4 = 2)

It's just like multiple conditions inside where. Instead, it will only join bannanas if "all" conditions are met.
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 05-31-2007, 02:08 PM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
thanks DJM. that's slick. i've always thought it was just to hook 2 tables together on an id.
__________________
testing 1 2 3
sde is offline   Reply With Quote
Old 06-01-2007, 12:50 AM   #4 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 635
DJMaze is on a distinguished road
"inner join" only show results from both tables if all conditions are met.
So if apples or bannanas has failed a condition there is no result for the record at all.
It's like: SELECT * FROM apples, bannanas

"right join" is the other way round of left join. First find the bannanas and then match an apple
__________________

UT: Ultra-kill... God like!
DJMaze is offline   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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
join help sde Everything SQL ( MySQL, MSSQL, DB2, Postgre, Oracle, etc...) 2 04-24-2007 11:57 AM
JOIN Syntax Help transfield PHP 3 05-25-2006 08:41 AM
Left outer join problem snauw Everything SQL ( MySQL, MSSQL, DB2, Postgre, Oracle, etc...) 4 02-01-2005 10:39 PM
SQL Query Help Please sde Program Design and Methods 6 03-07-2004 10:48 AM


All times are GMT -8. The time now is 08:02 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle