Re: Joining two MySQL tables

From: Date: Sun, 05 Nov 2000 02:46:40 +0000
Subject: Re: Joining two MySQL tables
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-23758@lists.php.net to get a copy of this message
LEFT JOIN ON A regular join will drop rows that don't have matches - LEFT JOIN does not AFAIK --Joe On Sat, Nov 04, 2000 at 07:45:13PM -0700, Brian T. Allen wrote: > Hi *, > > I am sure there is probably a simple solution to this, but it is eluding me... > > I have two tables: > > CREATE TABLE A ( > ID varchar(8) NOT NULL, > AMOUNT decimal(8,2) DEFAULT '0.00' NOT NULL, > PRIMARY KEY (ID) > ); > > CREATE TABLE B ( > ID int(8) NOT NULL auto_increment, > A_ID varchar(8) NOT NULL, > USED decimal(8,2) DEFAULT '0.00' NOT NULL, > PRIMARY KEY (ID), > ); > > Table A is for credits on an account, Table B is for purchases made against those credits. > > I want to generate a list of all credits and their balance, including those that haven't > been used at all: > > SELECT A.ID, A.AMOUNT, sum(B.USED) AS B_USED FROM A,B WHERE A.ID = B.A_ID GROUP BY A.ID > > This query works great except that it only lists credits from Table A that have a corresponding > listing (or multiple records) in Table B. > > Any suggestions? Is there a type of join for this? > > Thanks, > Brian ================================================================================ = Joe Stump joestump98@yahoo.com http://www.miester.org = ================================================================================ "Real programmers don't comment their code. It was hard to write, it should be hard to understand."

« previous php.general (#23758) next »