Click here to Skip to main content
15,923,273 members
Home / Discussions / Database
   

Database

 
Generaldate Pin
Anonymous6-Nov-03 2:26
Anonymous6-Nov-03 2:26 
GeneralRe: date Pin
Colin Angus Mackay6-Nov-03 3:59
Colin Angus Mackay6-Nov-03 3:59 
GeneralRe: date Pin
Anonymous6-Nov-03 4:36
Anonymous6-Nov-03 4:36 
GeneralRe: date Pin
Colin Angus Mackay6-Nov-03 4:49
Colin Angus Mackay6-Nov-03 4:49 
GeneralSQL Statement question. Pin
theJazzyBrain6-Nov-03 1:25
theJazzyBrain6-Nov-03 1:25 
GeneralRe: SQL Statement question. Pin
Roger Wright6-Nov-03 3:24
professionalRoger Wright6-Nov-03 3:24 
GeneralRe: SQL Statement question. Pin
theJazzyBrain6-Nov-03 5:53
theJazzyBrain6-Nov-03 5:53 
GeneralRe: SQL Statement question. Pin
Jeff Varszegi6-Nov-03 6:57
professionalJeff Varszegi6-Nov-03 6:57 
What about using EXISTS with a CASE statement? One of the nice things about EXISTS is that it only walks the index-- it doesn't have to retrieve a result set. In this case, it sounds like you are just wondering whether a child record exists or not.

SQL
SELECT 
   a.categoryId, 
   a.categoryParentId, 
   a.categoryName,
   (
      CASE 
         WHEN EXISTS(SELECT * FROM categories b WHERE b.categoryParentID=a.categoryID)
         THEN 1
         ELSE 0
      END
   ) AS categoryHasChildren
FROM categories a 
WHERE 
   a.categoryParentID=2 
   OR 
   a.categoryID=2


Especially if you are often-reading and seldom-updating the number of children, you may want to consider adding an extra column to each record containing the number of children. Then you could use triggers to update that column on the parent record when you add or remove a child.

Thank you.

Jeff Varszegi
GeneralRe: SQL Statement question. Pin
theJazzyBrain6-Nov-03 7:36
theJazzyBrain6-Nov-03 7:36 
GeneralRe: SQL Statement question. Pin
Jeff Varszegi6-Nov-03 7:39
professionalJeff Varszegi6-Nov-03 7:39 
GeneralRe: SQL Statement question. Pin
theJazzyBrain6-Nov-03 21:48
theJazzyBrain6-Nov-03 21:48 
GeneralRe: SQL Statement question. Pin
Jeff Varszegi7-Nov-03 2:43
professionalJeff Varszegi7-Nov-03 2:43 
GeneralRe: SQL Statement question. Pin
theJazzyBrain7-Nov-03 4:04
theJazzyBrain7-Nov-03 4:04 
Generaluser acces spermissions Pin
ranjjj6-Nov-03 0:10
ranjjj6-Nov-03 0:10 
GeneralRe: user acces spermissions Pin
perlmunger6-Nov-03 10:57
perlmunger6-Nov-03 10:57 
GeneralRe: user acces spermissions Pin
ranjjj6-Nov-03 17:36
ranjjj6-Nov-03 17:36 
GeneralRe: user acces spermissions Pin
perlmunger7-Nov-03 5:38
perlmunger7-Nov-03 5:38 
GeneralProblem in using OleDbDataReader Pin
sivaramakrishna5-Nov-03 22:14
sivaramakrishna5-Nov-03 22:14 
GeneralRe: Problem in using OleDbDataReader Pin
Mike Dimmick6-Nov-03 2:32
Mike Dimmick6-Nov-03 2:32 
GeneralRe: Problem in using OleDbDataReader Pin
sivaramakrishna7-Nov-03 19:06
sivaramakrishna7-Nov-03 19:06 
Generaldbo Pin
Hugo Hallman5-Nov-03 12:19
Hugo Hallman5-Nov-03 12:19 
GeneralSQL! Pin
Silly Boy5-Nov-03 6:18
Silly Boy5-Nov-03 6:18 
GeneralRe: SQL! Pin
Jeff Varszegi5-Nov-03 7:34
professionalJeff Varszegi5-Nov-03 7:34 
GeneralRe: SQL! Pin
andyharman5-Nov-03 11:49
professionalandyharman5-Nov-03 11:49 
GeneralEncoding problem using ADO Stream Pin
Firas Rashid4-Nov-03 2:59
Firas Rashid4-Nov-03 2:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.