Results 1 to 6 of 6

Thread: [RESOLVED] help looping my select statment

  1. #1

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Resolved [RESOLVED] help looping my select statment

    hey all,
    I have this...

    Code:
    select company,sum(minutes) from production_table as A
    right join customers as C
    on A.customerID=C.id 
    where C.id=1
    That returns a single row where c.id=1. How do eliminate the c.id=1 and return a row for every customer?

    I'm using mysql if it matters
    thanks
    kevin
    Last edited by kebo; Aug 25th, 2016 at 07:39 PM.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: help looping my select statment

    Am I missing something? Wouldn't you just remove the WHERE clause?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: help looping my select statment

    Removing the where clause was one of the first things I tried. When I did I ended up with the value of company field from the first row of table C and the sum total of all rows in table A.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  4. #4

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: help looping my select statment

    Here is the sql for the table creation if it helps...

    Table A:
    Code:
    CREATE TABLE `production_table` (
    	`id` INT(11) NOT NULL AUTO_INCREMENT,
    	`customerID` INT(11) NOT NULL,
    	`minutes` FLOAT NOT NULL,	
    	PRIMARY KEY (`id`),
    	INDEX `FK_production_table_customers` (`customerID`),
    	CONSTRAINT `FK_production_table_customers` FOREIGN KEY (`customerID`) REFERENCES `customers` (`id`)
    )
    COLLATE='utf8_general_ci'
    ENGINE=InnoDB
    AUTO_INCREMENT=92
    ;
    Table B:
    Code:
    CREATE TABLE `customers` (
    	`id` INT(11) NOT NULL AUTO_INCREMENT,
    	`company` VARCHAR(255) NOT NULL COLLATE 'latin1_general_ci',
    	PRIMARY KEY (`id`)
    )
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: help looping my select statment

    Add the Group By
    Code:
    select company,sum(minutes) from production_table as A
    right join customers as C
    on A.customerID=C.id 
    Group by company
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: help looping my select statment

    Marvelous.
    Thanks tg
    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

Posting Permissions

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



Click Here to Expand Forum to Full Width