473,659 Members | 2,666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

left join driving me crazy

Please help,

below is my problem. Let's say I have 2 tables, a Products table and a
Colors table that go as follow:

Table Products

prodID Name
1 shirt
2 tshirt
3 pants
4 jeans

and

Table Colors

prodID Colors
1 Blue
1 Red
2 Blue
3 Black
3 White
4 Blue
I want to find out all the products that come in Blue, and if not I
want to have the color empty. The result I want from my Query / SQL
Statement is:

prodID Colors Name...

1 Blue
2 Blue
3
4 Blue

What should my SQL statement/Query be like?

I tried:

Select Product.ProdID, Colors.Colors
From
Products
Left Join Colors
on Product.ProdID = Colors.ProdID
where Colors.Colors = "blue"

and this is what I get:

prodID Colors

1 Blue
2 Blue
4 Blue
Notice that prodID 2 doesn't show up but I want to return all prodIDs
whether or not they have a color Blue.

Please help...

Thanks
Nov 13 '05 #1
3 1612
Try creating a query that only returns Blue records from the Colors table:

SELECT prodID, Colors
FROM Colors
WHERE Colors = 'Blue'

Save that (for the sake of argument, call it qryBlue), then use it instead
of Colors in your Left Join:

Select Product.ProdID, qryBlue.Colors
From
Products
Left Join qryBlue
On Product.ProdID = qryBlue.ProdID

In newer versions of Access, this can actually be done in a single step:

SELECT Products.prodID , Sub.Colors
FROM Products LEFT JOIN
[SELECT prodID, Colors FROM Colors WHERE Colors = "Blue"]. AS Sub
ON Products.prodID = Sub.prodID;
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"Allan" <pr********@hot mail.com> wrote in message
news:7b******** *************** ***@posting.goo gle.com...
Please help,

below is my problem. Let's say I have 2 tables, a Products table and a
Colors table that go as follow:

Table Products

prodID Name
1 shirt
2 tshirt
3 pants
4 jeans

and

Table Colors

prodID Colors
1 Blue
1 Red
2 Blue
3 Black
3 White
4 Blue
I want to find out all the products that come in Blue, and if not I
want to have the color empty. The result I want from my Query / SQL
Statement is:

prodID Colors Name...

1 Blue
2 Blue
3
4 Blue

What should my SQL statement/Query be like?

I tried:

Select Product.ProdID, Colors.Colors
From
Products
Left Join Colors
on Product.ProdID = Colors.ProdID
where Colors.Colors = "blue"

and this is what I get:

prodID Colors

1 Blue
2 Blue
4 Blue
Notice that prodID 2 doesn't show up but I want to return all prodIDs
whether or not they have a color Blue.

Please help...

Thanks

Nov 13 '05 #2
pr********@hotm ail.com (Allan) wrote in
news:7b******** *************** ***@posting.goo gle.com:
Please help,

below is my problem. Let's say I have 2 tables, a Products
table and a Colors table that go as follow:

Table Products

prodID Name
1 shirt
2 tshirt
3 pants
4 jeans

and

Table Colors

prodID Colors
1 Blue
1 Red
2 Blue
3 Black
3 White
4 Blue
I want to find out all the products that come in Blue, and if
not I want to have the color empty. The result I want from my
Query / SQL Statement is:

prodID Colors Name...

1 Blue
2 Blue
3
4 Blue

What should my SQL statement/Query be like?

I tried:

Select Product.ProdID, Colors.Colors
From
Products
Left Join Colors
on Product.ProdID = Colors.ProdID
where Colors.Colors = "blue"

and this is what I get:

prodID Colors

1 Blue
2 Blue
4 Blue
Notice that prodID 2 doesn't show up but I want to return all
prodIDs whether or not they have a color Blue.

Please help...

Thanks


WHERE Colors.colors = "Blue" or colors.colors is Null

BOb Quintal
Nov 13 '05 #3
>
Select Product.ProdID, Colors.Colors
From
Products
Left Join Colors
on Product.ProdID = Colors.ProdID
where Colors.Colors = "blue"

and this is what I get:

prodID Colors

1 Blue
2 Blue
4 Blue
Well, if you want the empy ones also..then just add that condition....
where Colors.Colors = "blue" or Colors.Colors is null

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl************* ****@msn.com
http://www.attcanada.net/~kallal.msn
Nov 13 '05 #4

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

Similar topics

4
2528
by: dont bother | last post by:
This is really driving me crazy. I have a dictionary feature_vectors{}. I try to sort its keys using #apply sorting on feature_vectors sorted_feature_vector=feature_vectors.keys() sorted_feature_vector.sort() #feature_vector.keys()=sorted_feature_vector
2
16736
by: michael | last post by:
Gotta post because this is driving me nuts. Trying to DELETE orphans. I can successfully: SELECT GroupID FROM Groups LEFT JOIN Users ON UsersID = UserID WHERE UsersID IS NULL; but when I try: DELETE FROM Groups LEFT JOIN Users ON UsersID = UserID WHERE UsersID
4
1371
by: Denis St-Michel | last post by:
Hello All, Hope some Guru will be able to help me with this. Let's take this example table A ------------------------------------------------------------------------------- id | TicketNo | evaluation | Username ------------------------------------------------------------------------------- 1 1 9 Jamie 2 1 8.5 ...
3
1497
by: | last post by:
need some help with some sql I can't seem to get the syntax right. I've tried several but to no avail the one below gets me the closest but I can't get the guardians records pulled. SELECT SUM(tuition) FROM child INNER JOIN guardian ON guardian.ID = child.child_ID I would like the results to show the records from the guardian table as well tables: GUARDIAN
0
1304
by: Shapper | last post by:
Hello, I have this code in Global.asax: Sub Session_Start(Sender As Object, E As EventArgs) Dim cookie As HttpCookie = Request.Cookies("MyCookie") If Not cookie Is Nothing Then Response.Write(" * Cookie Exists * ") If Not cookie.Values("culture") Is Nothing
1
1604
by: Miguel Dias Moura | last post by:
Hello, I have been trying, for days, to retrieve a control's ClientId in a javascript function. I am using a master page and this is why I need to retrieve the Control's ClientId. The control Id is "Panel1". I placed "<%=Panel1.ClientID %>" in my HTML code and I got "ctl00_pPanel1". In my Javascript function I am using:
5
1708
by: Pupeno | last post by:
Hello, I am experiencing a weird behavior that is driving me crazy. I have module called Sensors containing, among other things: class Manager: def getStatus(self): print "getStatus(self=%s)" % self return {"a": "b", "c": "d"} and then I have another module called SensorSingleton that emulates the
3
2275
by: rashpal.sidhu | last post by:
Please help, this problem is driving me crazy !! I am using metaphone to create phonetic keys. When i run the module stand-a-lone it works fine. I'm trying to create a runner for informix which includes the function in order to allow me to call it from within a 4gl program. When i do this i get differences in the key that is produced????? This only happens when metahpone translates an x in a name. The stand
5
1762
by: mark4asp | last post by:
Every time the function below is called I get the alert. So I put a deliberate error in there and I check the value of (reportType=='MANDATE') in Firebug, which is found to be true. But still the alert comes up. Why? I checked the following watch expressions at the blah blah point. id = 5843 reportType = "MANDATE"
0
8427
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
8330
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,...
0
8746
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8523
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,...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6178
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
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2749
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

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.