Solved

select * rows has no Childe

Posted on 2014-02-28
5
214 Views
Last Modified: 2014-02-28
Dear all,
I need to get all records that has no reference in same table?

DicWords: DicWordID - ParentDicWordID

I need to list all records in Words where DicWordID not in ParentDicWordID
I use this:
select * from DicWords
where DicWordID not  in (select ParentDicWordID from DicWords  )
 
another saying : select all records has no Childe
thanks
0
Comment
Question by:ethar1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 39894745
The select statement you posted meets the requirements as you state them, so please clarify what you're trying to pull off here.  Some mockup data would be helpful.

>I need to list all records in Words
Is Words a separate table?
0
 

Author Comment

by:ethar1
ID: 39894793
Words is same DicWords
when I use :
select * from DicWords
where DicWordID not  in (select ParentDicWordID from DicWords  )
it return nothing
where :
 select * from DicWords where DicWordID=878251 return a record
and
 select * from DicWords where ParentDicWordID=878251 return nothing
0
 

Author Comment

by:ethar1
ID: 39894846
I just need delete all records like DicWordID= 4082
it has no Childe
Untitled-1.png
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 39894922
Be sure to exclude any NULL value from NOT IN, as a NULL value can cause a NULL result:

SELECT *
--DELETE FROM DicWords
FROM DicWords
WHERE
    DicWordID NOT IN ( SELECT ParentDicWordID FROM DicWords  WHERE ParentDicWordID IS NOT NULL )
0
 

Author Closing Comment

by:ethar1
ID: 39894997
Thanks
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question