Results 1 to 7 of 7

Thread: Sql Query Help

  1. #1
    Join Date
    Aug 2009
    Location
    CA, USA
    Posts
    34

    Question Sql Query Help

    databases:
    `log`
    `uploads`

    log parentid -> uploads parentid.

    I want to list all uploads by how many views they have. that number, the number of views, is the count of entries that are in the log database that match the parentid of the upload.

    How can i achieve this?

  2. #2
    Join Date
    May 2008
    Location
    Rutherford, NJ
    Posts
    68
    assuming 'name' as identifier for upload and 'id' as pkey for log

    select uploads.name,COUNT(log.id) as 'views'
    from uploads
    left join log on log.parentid=uploads.parentid
    group by uploads.id
    order by count(log.id) desc
    Database design and performance optimization, custom PHP scripts, and publicly available resources for developers!
    http://www.zeropride.com

  3. #3
    Join Date
    Aug 2009
    Location
    CA, USA
    Posts
    34
    Whenever i try any GROUP BY in an sql command the server just keeps on loading and never stops, i have to kill the process manually, im not sure whats wrong.

  4. #4
    Join Date
    Aug 2009
    Location
    CA, USA
    Posts
    34
    Any ideas?

  5. #5
    Join Date
    May 2009
    Posts
    766
    Have you tried this on a small, controlled data set?

  6. #6
    Join Date
    Aug 2009
    Location
    CA, USA
    Posts
    34
    yes, even on a table with 2 rows it times out.

  7. #7
    Join Date
    May 2009
    Posts
    766
    What's going on in your database error_log?

Similar Threads

  1. Need help with an SQL query
    By Lord Northern in forum Programming Discussion
    Replies: 5
    Last Post: 03-23-2008, 11:49 PM
  2. SQL Query - Need Help
    By Goldfiles in forum Programming Discussion
    Replies: 4
    Last Post: 12-28-2006, 11:16 PM
  3. sql query
    By orbitz in forum Programming Discussion
    Replies: 7
    Last Post: 11-10-2005, 11:31 AM
  4. Another query
    By myself1982 in forum Dedicated Server
    Replies: 5
    Last Post: 01-11-2005, 01:54 PM
  5. [PHP] SQL Query
    By djwayne_2004 in forum Programming Discussion
    Replies: 3
    Last Post: 01-05-2005, 05:58 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
  •