473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

conditional join

I have made a basic left join statement say "Select t.*, p.usenet_id
from usenet_group_1 u left join user_table t on u.id = t.usenet_id;
but only want the recordset to return values from user_table if field
in user_table have a certain value ( if usenet_group = 5 ) - can this
be done within the above sql statement or do i have to make 2 seperate
statements?

regards
Jakob
ou****@HaHapost6.tele.dk
Cut out the laughing if replying to email address
Dec 29 '05 #1
2 5783
Well - found the answer myself - it was really to easy: Just need to
add the field, ie;
"Select t.*, p.usenet_id, p.usenet_group from usenet_group_1 u left
join user_table t on u.id = t.usenet_id and p.usenet_group = 5;

:- |

On Thu, 29 Dec 2005 07:17:08 GMT, ou****@HaHapost6.tele.dk (Jakob
Outzen) wrote:
I have made a basic left join statement say "Select t.*, p.usenet_id
from usenet_group_1 u left join user_table t on u.id = t.usenet_id;
but only want the recordset to return values from user_table if field
in user_table have a certain value ( if usenet_group = 5 ) - can this
be done within the above sql statement or do i have to make 2 seperate
statements?

regards
Jakob
ou****@HaHapost6.tele.dk
Cut out the laughing if replying to email address


ou****@HaHapost6.tele.dk
Cut out the laughing if replying to email address
Dec 29 '05 #2
"Jakob Outzen" <ou****@HaHapost6.tele.dk> wrote in message
news:43****************@news.inet.tele.dk...
I have made a basic left join statement say "Select t.*, p.usenet_id
from usenet_group_1 u left join user_table t on u.id = t.usenet_id;
but only want the recordset to return values from user_table if field
in user_table have a certain value ( if usenet_group = 5 )


Yep, you can specify conditions in the ON clause of an outer join.
Rows that don't match are not included in the join.
For example:

SELECT t.*, p.usenet_id
FROM usenet_group_1 u LEFT OUTER JOIN user_table t
ON (u.id = t.usenet_id AND t.usenet_group = 5)

Regards,
Bill K.
Dec 29 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Alex | last post by:
Hi, I'm trying to do calculations in a SQL statement, but depending on one variable (a.type in example) I'll need to pull another variable from seperate tables. Here is my code thus far: ...
10
by: Ilik | last post by:
Hi all I'm trying to create a summery table of rain data that holds a record for every 0.1mm of rain in the following format: Station Name, Time, Value A, 2002-12-03 14:44:41.000, 0.1 A,...
5
by: chandy | last post by:
Hi, I am trying to change an SP from dynamic SQL to proper SQL but I can't figure a way to conditionally add extra parts to the statement. How can I do the equivalent of the following? ...
5
by: Bob Stearns | last post by:
As part of what I want in a report, I want the associated row from t2, if there is one, with the largest date in a range based on the base row from t1. I attempted the following: left outer join...
92
by: Raghavendra R A V, CSS India | last post by:
hie.. Do any one knows how to write a C program without using the conditional statements if, for, while, do, switch, goto and even condotional statements ? It would be a great help for me if...
2
by: Piper707 | last post by:
Hi, I need to know if there is any way of achieving conditional processing for XSD elements. --------------------------------------------------------------- <criteria></criteria> = a complex...
5
by: A.M | last post by:
Hi, I am using Python 2.4. I read the PEP 308 at: http://www.python.org/dev/peps/pep-0308/
3
by: msrviking | last post by:
Hello everybody, After several attempts of writing the query, I had to post my requirement in the forum. Here is what I have, what I need and what I did. Table A Col1 Col2 1 Nm1
6
by: simon.harris | last post by:
I have a query in an Access2000 db (created using the QBE as it happens!) that the resulting SQL looks like this; SELECT CLIENTS., Logfile., Logfile., SASTESTS.Cost, SASTESTS.*CLIENTS. AS...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.