faqts : Computers : Programming : Languages : PHP : Database Backed Sites : General

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

11 of 12 people (92%) answered Yes
Recently 10 of 10 people (100%) answered Yes

Entry

I have a customer DB and a transaction DB, how do I view a customer and their transaction history?

May 21st, 2001 17:21
Onno Benschop, Norton Seron, Ben Udall,


Given:
customer table
  id     name
  ---    -----
  1      peter
  2      paul
  3      mary
transaction table
  id     customer      action
  ---    ---------     -------
  1      1             added peter
  2      1             phoned peter
  3      1             sold dragon to peter
SELECT * FROM customer c,transaction t WHERE c.id=t.customer
You get:
  c.id   c.name   t.id   t.customer   t.action
  -----  -------  -----  -----------  ---------
  1      peter    1      1            added peter
  1      peter    2      1            phoned peter
  1      peter    3      1            sold dragon to peter