473,406 Members | 2,371 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,406 software developers and data experts.

How to group boolean expressions in a WHERE clause

102 100+
Expand|Select|Wrap|Line Numbers
  1. select * from cbomnew 
  2. where PartNumber not in 
  3.   (select PartNumber from cbom_filtered)
  4. and comCode= 'PCEC' || comCode='LOX' || comCode='CCEC' 
  5.  
i wan to select those partnumber which not in cbom_filtered.. but why the partnumber which exist in cbom_filtered still appear...?? my code correct???
Jun 24 '07 #1
13 4242
Atli
5,058 Expert 4TB
Because you need to group your boolean expressions together, or else it will evaluate them seperateley and return any row that matches any of them.

This is how your query should look:
Expand|Select|Wrap|Line Numbers
  1. select * from cbomnew 
  2. where PartNumber not in 
  3.   (select PartNumber from cbom_filtered)
  4. and  
  5. (    comCode= 'PCEC'
  6.   OR comCode='LOX'
  7.   OR comCode='CCEC' 
  8. )
  9.  
Jun 24 '07 #2
Atli
5,058 Expert 4TB
I have edited the thread's title to better describe it's contents.
Please read the Posting Guidlines before posting

Moderator
Jun 24 '07 #3
lyealain
102 100+
Pls advice me...

i have PartNumber and SupplierName as my primary key..

[PHP]"select * from cbomnew where PartNumber not in (select PartNumber from cbom_filtered) and (comCode= 'PCEC'or comCode='LOX'or comCode='CCEC' )"[/PHP]

how do i put like

select PartNumber and SupplierName not in( select PartNumber from cbom_filtered) ?????

i wan to compare 2 data which are partnumber and suppliername.. how do i do that...
Jun 24 '07 #4
pbmods
5,821 Expert 4TB
Heya, lyealain.

select PartNumber and SupplierName not in( select PartNumber from cbom_filtered) ?????
You'll want to use WHERE NOT EXISTS
Jun 24 '07 #5
lyealain
102 100+
[PHP] SELECT * FROM cbomnew WHERE NOT EXISTS (
SELECT * FROM cbom_filtered
WHERE cbomnew.partnumber = cbom_filtered.partnumber
AND[/b] cbomnew.suppliername = cbom_filtered.suppliername)
where (comCode= 'PCEC' or comCode='LOX' or comCode='CCEC' );[/PHP]

the above code give me error!!!!

i wan to select * where (comCode= 'PCEC' or comCode='LOX' or comCode='CCEC' ) and with these 2 constraints

[PHP]WHERE cbomnew.partnumber = cbom_filtered.partnumber
AND cbomnew.suppliername = cbom_filtered.suppliername)[/PHP]
Jun 24 '07 #6
pbmods
5,821 Expert 4TB
Heya, lyealain.

You have an errant '[/b]' in your SQL query. Is this intentional?
Jun 25 '07 #7
lyealain
102 100+
ohh.. sorry.. ignore that [/b]..
Jun 25 '07 #8
pbmods
5,821 Expert 4TB
Heya, lyealain.

What error does MySQL give you when you run that query?
Jun 25 '07 #9
lyealain
102 100+
hi.. very sorry for late reply...

i have updated my code to be like this...
[PHP]
dim qryFilter, rsReport
qryFilter= "select * from cbomnew where PartNumber + SupplierName not in (select PartNumber + SupplierName from cbom_filtered)and (RFQ='"&rfq&"')and (DateUploaded='"&lastup&"') and comCode IN (Select Distinct ComCode From comcode_table) "
[/PHP]
my idea is if the above not eof... then insert into cbom_filtered

but the above sentence keep inserting the same data into my cbom_filtered..

i have select something where not in the other table.. i wan to compare both PartNumber + SupplierName with cbom_filtered

cbomnew table: contains
partnumber: 123 SupplierName = angel
partnumber: 456 SupplierName = holy

in cbom_filtered table: contains
partnumber: 123 SupplierName = devil
partnumber: 456 SupplierName = ghost

if in cbom_filtered table: contains
partnumber: 123 SupplierName = angel
then don insert..
else .. insert..
Jul 7 '07 #10
lyealain
102 100+
help help... experts pls help...thanks thanks thanks..hahahhaha
Jul 8 '07 #11
pbmods
5,821 Expert 4TB
Try this:

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM `cbomnew` WHERE NOT EXISTS(SELECT * FROM `cbom_filtered ` WHERE (`cbom_filtered`. `PartNumber ` = `cbomnew `.`PartNumber`) OR (`cbom_filtered`. `SupplierName ` = `cbomnew `.`SupplierName`)) AND (`RFQ` = '" & rfq & "') AND (`DateUploaded` = '" & lastup & "') AND EXISTS(SELECT * FROM `comcode_table` WHERE `comcode_table`.`ComCode` = `cbomnew`.`ComCode`)
Make sure your `cbomnew`, `cbom_filtered` and `comcode_table` tables are indexed on `PartNumber`, `SupplierName`, `RFQ`, `DateUploaded` and `ComCode`.

http://dev.mysql.com/doc/refman/5.0/...ubqueries.html
Jul 8 '07 #12
lyealain
102 100+
[PHP]WHERE (`cbom_filtered`. `PartNumber ` = `cbomnew `.`PartNumber`) OR (`cbom_filtered`. `SupplierName ` = `cbomnew `.`SupplierName`)
[/PHP]
thanks.. should i put 'or' / 'and' for the above statement that u specified..

i think is AND??? because i wan to include both partnumber and suppliername to compare with other table at the same time
Jul 9 '07 #13
pbmods
5,821 Expert 4TB
Heya, lyealain.

i think is AND??? because i wan to include both partnumber and suppliername to compare with other table at the same time
The query I posted will return a result if either one exists. If you only want to return results that have both values, then you are correct; you'll want to change that to AND.
Jul 9 '07 #14

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

Similar topics

3
by: Robby McGehee | last post by:
I need this to work: SELECT FROM WITH (NOLOCK) where ='a' GROUP BY , HAVING COUNT () > 1 The problem is that I get an error that needs to be in the GROUP BY clause or aggregate function. if...
4
by: Chad Richardson | last post by:
I've always been mistified why you can't use a column alias in the group by clause (i.e. you have to re-iterate the entire expression in the group by clause after having already done it once in the...
5
by: Mad Scientist Jr | last post by:
Has anyone worked on code that that can parse evaluation expressions (could be numbers or strings) like ( ( "dog" = "dog" ) or "foo" = "bar" ) and ("cow" = "bat" and "bye" = "hi") or ("math" =...
2
by: aj70000 | last post by:
This is my query select ano,max(date),a_subject from MY_TAB where table_name='xyz' and ano=877 group by a_subject,ano order by a_subject ANO max(Date) A_Subject 877 2005-01-20...
2
by: JJA | last post by:
Please advise on how to get the GROUP BY coded in an acceptable way: DECLARE @LO INT DECLARE @HI INT DECLARE @StartDate varchar(10) DECLARE @EndDate varchar(10) SELECT @StartDate =...
2
by: webposter | last post by:
Hi, I am looking for information on a data structure (and associated algorithm) to do short-circuit evaluation of boolean expressions and haven't found a single one even after googing for two...
12
by: Bill Moran | last post by:
Hey all. I've hit an SQL problem that I'm a bit mystified by. I have two different questions regarding this problem: why? and how do I work around it? The following query: SELECT GCP.id,...
1
by: bflemi3 | last post by:
My previous post went unanswered. I now know what the problem is but can not think of a practical work around. Hopefully by making my question less confusing someone will be able to help...here...
0
amitpatel66
by: amitpatel66 | last post by:
Oracle 10g feature: Regular Expressions This article will provide information about regular expressions in oracle 10g which the forum members might find it useful. The regular expressions...
6
by: MM | last post by:
Hello users. I have a query that I can run and see the result on the grid on design time, but when i run the program i get the folowing message:ORA-00979: not a GROUP BY expression. When I run the...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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
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...
0
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
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
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,...

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.