473,320 Members | 1,746 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,320 software developers and data experts.

where not exists

Why the first statement is not working.
I want to use EXCEPT

connect to UDBPERF;

select dept_id from new.dept m except (select 1 from new.dept p where
p.parent_d = m.member_id and m.hirachy level_id = '50');
select dept_id from new.dept m where not exists (select 1 from new.dept
p where p.parent_d = m.member_id and m.hirachy level_id = '50');
cheers.....

Nov 12 '05 #1
4 1881
After the EXCEPT is a different (not nested) subselect from the one before
EXCEPT - hence table references aren't carried over.

James Campbell

--
Message posted via http://www.dbmonster.com
Nov 12 '05 #2

radhika wrote:
Why the first statement is not working.
I want to use EXCEPT

connect to UDBPERF;

select dept_id from new.dept m except (select 1 from new.dept p where
p.parent_d = m.member_id and m.hirachy level_id = '50');


EXCEPT is a setoperator (similar to union and intersect), and exists is
a predicate. Therefore you cannot reference m.member_id

/Lennart

Nov 12 '05 #3
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are. Sample data is also a good idea, along with clear
specifications.

The immediate problem is that EXCEPT [ALL] is defined like UNION [ALL]
and INTERSECT [ALL] to work with completed table expressions on the
same level, so you cannot have containing reference, as you do with
subqueries. However, there are better ways to model hierarchies, so
you might want to get a copy of my book TREES & HIERARCHIES IN SQL.

Nov 12 '05 #4
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are. Sample data is also a good idea, along with clear
specifications.

The immediate problem is that EXCEPT [ALL] is defined like UNION [ALL]
and INTERSECT [ALL] to work with completed table expressions on the
same level, so you cannot have containing reference, as you do with
subqueries. However, there are better ways to model hierarchies, so
you might want to get a copy of my book TREES & HIERARCHIES IN SQL.

Nov 12 '05 #5

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

Similar topics

3
by: KathyB | last post by:
Hi, I have 2 tables: tblStations StationID Station tblStationUser RecordID UserName Station I'm trying to come up with a dataset that contains the
6
by: Michael | last post by:
I have two tables with a 1-many relationship. I want to write a select statement that looks in the table w/many records and compares it to the records in the primary table to see if there are any...
2
by: Rotsj | last post by:
Hi, if i run the following query: select * from std_order_lines sol where exists(select * from std_orders so, customers c where so.customers_id = c.customers_id and c.test_customer = 'Y' and...
4
by: stoppal | last post by:
I need some help. I am trying to write a query which does the following SELECT * from table1 where field1=(SELECT distinct field1 FROM table1 WHERE field2='2005' or field2='2010')
7
by: robert | last post by:
i need to update a column which is a member of the PK on this table. there are some thousands of rows to be updated, many more thousand already in the table. so, i get a constraint violation...
4
by: Jacinle Young | last post by:
Hi all, I have written the SQL but it doesn't work db2 "select acode from t1 where (acode) not in (select eid from t2 where iid ='0') and iid ='0'" select nothing but the following works
6
by: Roy Gourgi | last post by:
Hi, I am trying to add a row to my table but I get the error message "invalid column name SOBN and BN1" on this statement. Basically, I am trying to add the row into the same table that I am...
10
by: Paul Cheetham | last post by:
Hi, I am developing an application that needs to store some machine-specific settings. The application is going to be published on the network in order to keep the clients on the latest version....
1
by: bpforte | last post by:
Hello, I need help with building query, basically I need to select all records from one table that don't exists in second table with status 1, but they can exists in second table with status 0, to...
3
by: ckauvar | last post by:
I've got a SQL statement that has me stumped. Consider the following scenario: A donor gives the following gifts: in 2006 they give $250 in 2007 they give $550 in 2008 they give $50 My...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.