Solved

select * rows has no Childe

Posted on 2014-02-28
5
205 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
  • 3
5 Comments
 
LVL 65

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:
ScottPletcher 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how the fundamental information of how to create a table.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now