SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Apr 2003
    Posts
    332
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Subquery returns more than one row.

    I need to count the number of unique visitors attending during any period, with a sum of each status. This query returns the error "Subquery returns more than one row." How can I work around this?

    Code:
    CREATE TABLE `memlog` (
    	`log_id` INT(10) NOT NULL AUTO_INCREMENT,
    	`m_id` INT(10) NOT NULL,
    	`name` VARCHAR(60) NOT NULL DEFAULT '\'\'',
    	`date` DATE NOT NULL DEFAULT '0000-00-00',
    	`status` VARCHAR(10) NOT NULL DEFAULT 'Verified',
    	PRIMARY KEY (`log_id`)
    )
    query:

    Code:
    SELECT  COUNT(`status`),`status` FROM memlog 
    WHERE (`date` BETWEEN '2011-01-01' AND '2011-03-01')
    AND (SELECT DISTINCT m_id FROM memlog)
    GROUP BY `status`
    Thanks,

    Andy

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,501
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Code:
    SELECT 
        `status`
      , COUNT(DISTINCT m_id) AS total
    FROM memlog
    WHERE `date` BETWEEN '2011-01-01' AND '2011-03-01'
    GROUP BY `status`

  3. #3
    SitePoint Addict
    Join Date
    Apr 2003
    Posts
    332
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Super! Thanks, Guido.


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
  •