|
-
May 25th, 2004, 11:57 AM
#1
Thread Starter
Hyperactive Member
a simple sql problem
Hi friends,
I am stuck in solving the sql query.PI am not good at sql query,Please give me the solution ion this.
In my table, there are 3 fields say MainId, Name and parentId.
MainId is auto increment field and ParentId store the value of MainId.
a) Now I want to find the name and their parentId
b) Count of ParentId for the mainId.
How do I get in sql query.
Thsnks & Regsrds
PPCC
-
May 25th, 2004, 12:19 PM
#2
Hyperactive Member
This code should do the trick, you need to replace MAINID with the value you are looking for...
SELECT COUNT(ParentID) FROM [TABLE] WHERE ParentID = MAINID
-
May 25th, 2004, 12:44 PM
#3
Hyperactive Member
I'm not sure to understand. I suppose you want to choose a name, perhaps from a list, and find all records with same parent id. Probably you could use nested query, but I don't remember well the sintax
So I suggest to find, before, the parentid from Name:
"SELECT parentid FROM MyTable WHERE Name='" & StrName & "'"
StrName is a string which contains the name you selected
Now you have parentid and you can assign its value to a variable (AS LONG) that I call IDP
"SELECT * FROM MyTable WHERE ParentID=" & IDP.Tostring
In this way you select all records with ParentID=IDP
If you want their number, for a particular IDP:
"SELECT COUNT(*) AS Total FROM MyTable WHERE ParentID=" & IDP.Tostring
In 'Total' you obtain the sum of all records with ParentID=IDP
I'm using only my memory, because I've not your database to test my queries, so it's possible they aren't right. I can't be sure about this point. Sorry!
Live long and prosper (Mr. Spock)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|