Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my table has following records

Menuid  Menuname         Navigation URL              ParentID
1	Company Details 	#	             11
101	Create Company	NewCompany.aspx?id=	      1
2	Branch Details	#	                     11
201	Create Branch	NewBranch.aspx?id=	      2
4	Menu List	MenuList.aspx?id=	     11
5	Administrator	#	                     11
6	Master   	#	                   NULL
601	Ledger Group	LedgerGroup.aspx?id=	      6
603	Item	          #	                      6
6031	New Item	NewItem.aspx?id=	    603
604	Ledger   	#                       	6
6041	New Ledger	NewLedger.aspx?id=	     604
7	Entry	         #               	    NULL
606	Price List	#	                       6
6061	Item Wise Price List	NewPWPrice	     606
6062	Party Wise Price List	NewIWPrice	     606
701	Purchase	#	7
7011	New Purchase	NewPurchase.aspx?id=	    701
702	Sales	         #	                      7 
7021	New Sales	NewSales.aspx?id=	         702
7022	Alter Sales	AlterSales.aspx?id=      	702
7014	Display 	DisplayPurchase.aspx	        701
704	Purchase Return	#	          7
7041	Create Return	NewPurchaseReturn.aspx?id=	704
703	Sales Return	#	7
7031	Create Return	NewSalesReturn.aspx?id=  	703

In this above table I want to check the all the parentid exists in menuid column

How to do it? Please help me
Posted
Updated 8-Aug-12 19:36pm
v2
Comments
Pasan Eeriyagama 9-Aug-12 1:44am    
Try
select * from TABLE1 where parentid NOT in (select menuid from TABLE1)

1 solution

SQL
select parentid  from tbl where parentid  not in (select menuid from tbl)


or

use not exists

SQL
select parentid  from tbl where not exists (select menuid from tbl)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900