SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Count Joining Multiple Tables

    Working on a query that I'm pretty sure is out of the scope of my skills. I've done fine thus far with simple queries contained within 1 table but I'm not sure how to go about this. Here's the pseudo-code I have currently.

    Tables needed:
    work_orders (column for unique_id, column for assigned tech_id)
    techs (unique tech_id, tech_name)

    I'm trying to get the query to list 2 columns. The first is a list of all the techs. The second is a count of all the work_orders that are assigned to their corresponding tech_id.
    Code:
    tech_name  wo_count
    ---------  -------
    Jimmy      12
    Bobby      23
    Please let me know if more information is needed to assist. Thanks for any help.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Code:
    select tech_name
         , count(*) as  wo_count
      from techs
    left outer
      join work_orders
        on techs.tech_id 
         = work_orders.tech_id
    group
        by tech_name
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow, you're awesome! Works great =]

    And if you have a second... I'm all self taught when it comes to this stuff, mostly learning from debugging other peoples code and looking up things on msdn or w3c from time to time. Would you recommend anything beyond posting here when I get stuck? A book, nice manual with good examples, or any tips for learning? I'd much rather be able to do this on my own but I'm really in awe that there is a community like this to help people (beginners are people too!) out.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    check out some of the tutorials on my SQL Links page
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks great, I'll check it out.
    Thanks again!


Bookmarks

Posting Permissions

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