SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Utah, USA
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Quick join/subquery help

    Hi guys,

    I'm trying to pull a count of termIDs from one table and the term_name from another table.

    Here's the query that's working to get the count:

    SELECT value AS tid, COUNT(value) AS count FROM `notifications_fields` WHERE field = 'tid' GROUP BY value ORDER BY count DESC;

    Now I need to pull the term_name from the term_data table. Both tables (notifications_fields and term_data) have tid columns.

    Thanks!
    Kevin

  2. #2
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    695
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Code:
    select value AS tid, 
           term_name,
           count(value) as count 
      from notifications_fields
      join term_data
        on notifications_fields.tid = term_data.tid
     where field = 'tid' 
     group by value,
           term_name
     order by count desc

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Utah, USA
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you swampBoogie!


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
  •