473,809 Members | 2,780 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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****@HaHapost 6.tele.dk
Cut out the laughing if replying to email address
Dec 29 '05 #1
2 5800
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****@HaHapost 6.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****@HaHapos t6.tele.dk
Cut out the laughing if replying to email address


ou****@HaHapost 6.tele.dk
Cut out the laughing if replying to email address
Dec 29 '05 #2
"Jakob Outzen" <ou****@HaHapos t6.tele.dk> wrote in message
news:43******** ********@news.i net.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
65478
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: select a.DeptCode DeptCode, a.Type Type,
10
2035
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, 2002-12-03 14:45:45.000, 0.1 A, 2002-12-03 14:49:45.000, 0.1 A, 2002-12-09 05:30:35.000, 0.1 A, 2002-12-09 05:30:37.000, 0.1
5
14642
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? DECLARE @arg NVARCHAR(10) SELECT a.i, a.x FROM aTable a
5
4267
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 IS3.service_ai t2 on T1.dam_BHID=T2.cow_BHID and t2.datex = (select max(datex) from is3.service_ai where days(datex) < (days(t1.birth_date)-283+45) and days(datex) > (days(t1.birth_date)-283-45) )
92
9916
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 someone helps me... Urgent - Please reply soon ! Thanks, Raghu
2
5384
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 element <join_condition></join_condition> = a simple element --------------------------------------------------------------- EX:
5
1702
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
3743
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
15051
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 RealCost
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10387
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7662
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5689
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.