|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
"count" query
i need to query the following tables to return a category name,category description, username of user who made category and no. of posts in each category.i am using this for a blog i am developing which needs to display a list of categories including category description, user who posted the category and no. of posts in the category
i have been using the following query but doesnt seem to work for me select C.CATEGORY_NAME,C.DESCRIPTION,U.USER_ID,count(P.PO ST_ID) from CATEGORY C,REGISTERED_USER U,POST P where P.CATEGORY_ID = C.CATEGORY_ID; the error message i am getting is ERROR at line 1: ORA-00937: not a single-group group function SQL> desc REGISTERED_USER; Name Null? Type ----------------------------------------- -------- ---------------------------- USER_ID NOT NULL NUMBER USERNAME NOT NULL VARCHAR2(10) PASSWORD NOT NULL VARCHAR2(10) SQL> desc CATEGORY; Name Null? Type ----------------------------------------- -------- ---------------------------- CATEGORY_ID NOT NULL NUMBER CATEGORY_NAME NOT NULL VARCHAR2(255) USER_ID NUMBER DESCRIPTION VARCHAR2(255) SQL> desc POST; Name Null? Type ----------------------------------------- -------- ---------------------------- POST_ID NOT NULL NUMBER CATEGORY_ID NUMBER USER_ID NUMBER POST_TITLE NOT NULL VARCHAR2(255) DATE_CREATED NOT NULL DATE POST_BODY_TEXT NOT NULL VARCHAR2(255) i used the following commands to create the above tables create table REGISTERED_USER ( USER_ID number primary key, USERNAME varchar2(10) not null, PASSWORD varchar2(10) not null ); create table CATEGORY ( CATEGORY_ID number primary key, CATEGORY_NAME varchar2(255) not null, DESCRIPTION varchar2(255), USER_ID references REGISTERED_USER ); create table POST ( POST_ID number primary key, CATEGORY_ID references CATEGORY, USER_ID references REGISTERED_USER, POST_TITLE varchar2(255) not null, DATE_CREATED date not null, POST_BODY_TEXT varchar2(255) not null ); thanks |
|
#2
|
||||
|
||||
|
I forget the formal explanation, but you need to have a GROUP BY clause if you're using certain methods while joining multiple tables.
Try the following: Code:
select C.CATEGORY_NAME,C.DESCRIPTION,U.USER_ID,count(P.PO ST_ID) from CATEGORY C,REGISTERED_USER U,POST P where P.CATEGORY_ID = C.CATEGORY_ID group by C.CATEGORY;
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter! DevArticles Forum Moderator "The net is a waste of time, and that's exactly what's right about it." -- William Gibson |
|
#3
|
|||
|
|||
|
lol.. did I just "Agree" to a MadCowzz explanation? Wonder if Einstein would be impressed if a n00b told him "Yes, your theory is correct but only if..."
![]() |
|
#4
|
||||
|
||||
|
Ya, uh, I left taht one vague on purpose... at least that's my story and I'm sticking to it!
Thanks for the followup Laban |
![]() |
| Viewing: Dev Articles Community Forums > Databases > General SQL Development > "count" query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|