Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8145287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:36:58+00:00 2026-06-06T13:36:58+00:00

I have two tables: projects and tasks. A project consists of tasks. I want

  • 0

I have two tables: projects and tasks. A project consists of tasks. I want to create a view, where all the projects are listed with the amount of tasks, that are related to the project. This is what I’ve tried:

    SELECT 
   "PROJECTS"."P_ID" "P_ID", 
  (
    SELECT
        COUNT(*)
    FROM
       "TASKS"
    WHERE 
      "TASKS"."PROJECT" = "PROJECTS"."P_ID"
 ) AS "Amount of Tasks" 
 FROM
     "PROJECTS", "TASKS"

 WHERE "TASKS"."PROJECT"="PROJECTS"."P_ID"

Unfortunately it returns a project several times, depending on the amount of tasks they have. Project 1 for example has 3 tasks, so it shows up 3 times in the tableview. How can i prevent that? I tried to add distinct after the first select but i got this error:

ORA-01791: not a SELECTed expression

Any help is appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T13:37:00+00:00Added an answer on June 6, 2026 at 1:37 pm

    You would generally want to join the two tables and do a GROUP BY. Something like

    SELECT p_id, count(*)
      FROM projects,
           tasks
     WHERE tasks.project = projects.p_id
     GROUP BY p_id
    

    If you really want to use the scalar subquery approach (this will be less efficient), you could do something like

    SELECT p_id,
           (SELECT COUNT(*)
              FROM tasks
             WHERE tasks.project = projects.p_id)
      FROM projects
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables, tasks and projects. And every task has a project (and
I have two tables: entitytype and project . Here are the create table statements:
I have two tables, employees and project , in listbox2 , I show all
Hi all i have two tables Projects ---------- ProjectID|ProjectNAme 1 |asdasd 2 |adas 3
Let's say I have two tables in a database: projects and users. I create
I have two tables: Projects and ProjectsData and I want to execute query with
OK, so I have two tables I'm working with - project and service ,
I'm designing a project for quizzes and quizz results. So I have two tables:
I have two tables, activities and activity_tours . activities hasMany activity_tours and are related
I have two tables: one called Projects, and another called Documents (projects has many

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.