Reply to MySQL -- query that displays rows that can't be joined

Your name:

Reply:


Posted by laredotornado on 11/28/05 16:16

Hello, I'm using PHP 4 and MySQL 4. Is it possible to write a query
that joins two tables, but if one value cannot be matched, the row
would not be excluded, but a value could be substituted. For example,
if there were two tables

SALES
----------
USER_ID INTEGER UNSIGNED,
TOTAL_SALES FLOAT

and

USERS
-----------
USER_ID INTEGER UNSIGNED,
USERNAME VARCHAR(32) NOT NULL

and they contained the following data

SALES.USER_ID SALES.TOTAL_SALES
-----------------------------------------------------------------
4 55.00
2 125.50

USERS.USER_ID USERS.USERNAME
--------------------------------------------------------------
2 myusername

How could I write a single query tnat would give the following results?

USERNAME TOTAL_SALES
---------------------------------------------------------------
myusername 125.00
(user no longer exists) 55.00

Thanks for your help, - Dave

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация