Navigate
Home
ArticleWiki
Forum
Journal
Search
Newsletter
Links
Tech News
expertsrt.com
Welcome Guest.
Username:

Password:

Remember me

need help contructing an SQL stament
Welcome, Guest. Please login or register.
December 03, 2008, 02:47:56 PM
11305 Posts in 1249 Topics by 498 Members
Latest Member: katCheeme
Experts Round Table Network  |  Databases  |  MySQL  |  need help contructing an SQL stament « previous next »
Pages: [1]
Author Topic: need help contructing an SQL stament  (Read 1392 times)
thepreacher

Offline Offline

Posts: 78


« on: April 13, 2007, 10:12:10 AM »

I am using MySQL version 4 and i need help in constructing an SQL stament. I need to retrive 3 sets of information from 3 different tables. The tables are Recipient, Customer and Transaction. The relationship is as follows: The customerID can be found in both the Recipient and Transaction tables. The Recipient ID can be found in the Transaction table.

From the recipient table i need firstname, lastname and address. From the Customer table i need the firstname and surname. From the Transaction table i need the transaction date and the transaction amount.

I will be delighted if someone can help. I have never written a mysql join sql comprising more than 2 tables before.

Thanks.
Logged
VGR
Mentor

Offline Offline

Posts: 682



WWW
« Reply #1 on: April 15, 2007, 12:57:25 AM »

you've all the "billes" to solve the problem yourself ;-)

select c.transaction_date,c.trans_amount,a.firstname,a.lastname,a.address,b.firstname AS cust_fst, b.surname AS cust_surn  from transaction AS c LEFT JOIN recipient AS a ON (a.id=c.recipient_id) LEFT JOIN customer AS b ON (b.id=c.cust_id);

your problem lied in :
- assigning ALIASES to tables referenced in a JOIN (MySqld can do this)
- assigning ALIASES to columns being synonyms (firstname and surname, mainly)
Logged

techie overlord, answers all kind of questions on http://www.europeanexperts.org
Pages: [1]
« previous next »
    Jump to: