473,505 Members | 13,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SELECT statement problem

228 New Member
Hi,

I have this 3 tables:
Expand|Select|Wrap|Line Numbers
  1. tblProducts: productid,producntname
  2. tblIngredient:ingredientid,ingredientname
  3. tblProductsIngredients:autoid,productcode,ingredientcode,amountneeded
  4.  
Products are made by certain amount of ingredients. I can add new products and all but am having problem wit updating product. During editing product, I want to list ingreidents that are not already added to the product along with ingredients (and their amounts) that are already specified for the product. I tried this code but it only returns already specified products while sometimes adds only one new ingredient to the list to be added:

Expand|Select|Wrap|Line Numbers
  1.  
  2. $strsql="SELECT * FROM viewexistingandnewingredientswithproducts WHERE productcode=$id OR productcode IS NULL";
  3.  
  4. }
  5.  
where viewexistingandnewingredientswithproducts is defined as

Expand|Select|Wrap|Line Numbers
  1.  
  2. select * from tblingredients,tblProductsIngredients where ingredientid=ingredientcode
  3.  
Aug 7 '12 #1
1 1212
Rabbit
12,516 Recognized Expert Moderator MVP
What you've done is basically an inner join. It will never show ingredients that aren't in the product. What you want to do it outer join the tables.
Aug 7 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2456
by: ghasem | last post by:
Dear mySQL community, I have once again turned to the user groups for a problem I cannot solve myself! Atually, I have read all I can from the newsgroups on this but I could not solve it myself....
13
1886
by: kieran | last post by:
Hi, I have the following SQL statement which is pulling a few details from a database. As you can see, there is only the one table from which i am creating a temporary copy. The reason I do...
2
1453
by: ray well | last post by:
i have to extract info from a legacy access database, which i can't alter, or run APPEND or UPDATE quries against. i can only use SELECT statments to extract what i need. the database has...
8
4698
by: | last post by:
Hello, This is gonna sound real daft, but how do I test a Select Case statement for variants of a theme? Here's a snippet of my code... Select Case sUsr Case "Guest", "TsInternetUser",...
7
1693
by: farid25 | last post by:
I have 3 tables t_studends --------- student_id student_name ---------- ...
5
7086
by: JamesHoward | last post by:
I have a problem with python's asyncore module throwing a bad file descriptor error. The code might be difficult to copy here, but the problem is essentially: The server wants to sever the...
2
2903
by: willwmagic | last post by:
Hi everyone, I feel as this is a very simple question, but I cannot find any information pertaining to it. I want to be able to update a set of records that were returned through a select...
2
1529
by: gool | last post by:
Hi, I am writing this piece of code: $sqlquery="WITH journey (TO_TOWN, STEPS, DISTANCE, WAY) AS (SELECT DISTINCT JNY_FROM_TOWN, 0, 0, CAST('PARIS' AS VARCHAR(MAX)) FROM T_JOURNEY ...
3
1706
by: micky125 | last post by:
Hey guys I have been checking the forum for a way to populate a second select field depending on the choice made from the first one. Basically i am working on projects and the delays that occur. The...
2
4814
by: ankitmathur | last post by:
Hi All, I'm facing a problem I'm unable to find a solution for. I hope fellow members would be able to help me out. System Info: PHP v5 MSSQL 2008 Linux box
0
7098
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...
0
7298
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,...
1
7017
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...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5610
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,...
0
3187
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...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1526
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 ...
0
406
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...

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.