Results 1 to 3 of 3
  1. #1

    Counting 2 statements


    I have 2 sql statements
    1) select count(task_id) as count_task from tbl_employee_task,tbl_employee where
    tbl_employee_task.employee_id = tbl_employee.employee_id group by task_id

    2) select count(todo_id) as count_todo from tbl_employee_todo,tbl_employee where
    tbl_employee_todo.employee_id = tbl_employee.employee_id group by todo_id

    now what I want to display is a list with all the employees who have tasks + todo

    is there a way to do it in one sql statement?


  2. #2
    Join Date
    May 2008
    Knowing the schema might help some; e.g., are task_id and todo_id non-unique in their respective tables? What other identifying information is in the tbl_employee table?

    Something like "select as Name, count(ta.*) as Tasks, count(to.*) as Todos from tbl_employee e inner join tbl_employee_task ta on (e.employee_id=ta.employee_id) inner join tbl_employee_todo to on (e.employee_id=to.employee_id) group by;" may work, but there's not really enough data supplied... ;-)
    Dan Hildebrandt, Developer / Support, WebGroup Media LLC. -
    Cerberus Helpdesk 5.x is a CRM toolkit. Remember anything about anybody, swiftly reply to a flood of e-mail,
    capture feedback organically, track time, flag opportunities, share tasks, and more.

  3. #3
    Join Date
    Mar 2007
    Phoenix, AZ, United State
    select * from tbl_employee where (select count(*) from tbl_employee_task where employee_id = tbl_employee.employee_id);

    As an alternative option to what Hildy suggested

Similar Threads

  1. mysql_query - while statements?
    By thomase in forum Programming Discussion
    Replies: 1
    Last Post: 09-14-2008, 12:57 PM
  2. PHP, MySQL and If Statements (Echo)
    By smellybob in forum Web Design and Content
    Replies: 1
    Last Post: 07-06-2007, 06:55 PM
  3. Hearing set on signing statements
    By case in forum Web Hosting Lounge
    Replies: 2
    Last Post: 06-30-2006, 01:13 PM
  4. LIKE Operator for IF Statements?
    By twooly in forum Programming Discussion
    Replies: 3
    Last Post: 02-22-2004, 06:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts