SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Count help

  1. #1
    SitePoint Wizard Darren884's Avatar
    Join Date
    Aug 2003
    Location
    Southern California, United States
    Posts
    1,616
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Count help

    Hi I am using the following queries
    SELECT * FROM $topics_table WHERE board_id = '{$row2['board_id']}'

    SELECT * FROM $replies_table WHERE board_id = '{$row2['board_id']}'

    then I do the query results and a mysql_num_count for each then I add them to together with a variable. So there is 1 row in topics table and 1 row in the replies table. Is there anyway to combine these queries? ANy way at all, or is it impossible in mysql?
    Have a good day.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    here ya go --
    Code:
    select one + two as four
      from ( 
           select count(*) as one 
             from $topics_table 
            WHERE board_id = {$row2['board_id']}
           ) as five
    cross
      join ( 
           select count(*) as two 
             from $replies_table 
            WHERE board_id = {$row2['board_id']}
           ) as seven
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •