Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default selct with a count

    Hi guys! How can I count comments to my pages within a pages list query (like
    replyes in a forum topic list) My DB is MySQL Here is a query I've done
    select folders.ID, folders.name, folder_comments.folder_id, COUNT(folders.ID IN
    (folder_comments.folder_id)) AS cnt from folders, folder_comments WHERE
    folders.Parent_ID = 77 AND folders.Status = 2 GROUP BY folders.id it returns
    some list with the same CNT value for each entry. Please help me! Thank you.

    ser_g Guest

  2. Similar Questions and Discussions

    1. how to count?
      Hi there, I am doing a count on two tables and do want to know how many rows will be returned back. Unfortunatelly the result is instead of 3 is...
    2. Count ()
      Hi All, I wonder if anybody can help, I have a search page with two field, 'cboLeadStatus' and 'cboTSRs' that pulls records from tblLeadDetails...
    3. [PHP] COUNT(*)
      Actually that does retrieve the number of rows.. // Query $query = "SELECT COUNT(*) AS count FROM pet"; // Execute Query $result =...
    4. COUNT(*)
      use mysql_fetch_rows(); $result="SELECT COUNT(*) FROM pet"; $sql=mysql_query($result); $number_of_rows = mysql_fetch_rows($sql); while...
    5. count
      I have the following query: select * from NormalizedData_Out n inner join MaxDate_Out m on n.SID= m.SID and n.DateEntered=m.maxdate (select...
  3. #2

    Default Re: select with a count

    It looks like your missing a join between the two tables.

    folders.ID = folder_comments.ID

    eastinq Guest

  4. #3

    Default Re: select with a count

    Since you are using MySQL, it would depend on what version you are using, since
    you can not use SUB-SELECTS with MySQL versions prior to 4.1 If you have 4.1,
    then something like the attached query may work, although I'm uncertain about
    the relationship between folder and folder_comment. I am assuming that
    folder.id = folder_comment.folder_id.

    Phil



    SELECT f.ID,
    f.name,
    fc.folder_id,
    (SELECT COUNT(f1.ID)
    FROM folders AS f1
    WHERE f1.ID = fc.folder_id) AS cnt
    FROM folders AS f,
    folder_comments AS fc
    WHERE f.Parent_ID = 77
    AND f.Status = 2
    AND f.id = fc.folder_id
    GROUP BY f.id

    paross1 Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139