This topic is locked

Showing Data From Two Tables on One Report

9/16/2007 9:23:44 PM
PHPRunner General questions
D
dilbertbert author

This is probably a no-brainer for most but I'm a bit of a newbie in mysql query:
If anyone could give me an example of the "Edit SQL Query"
I need to creat a Pickup Ticket for a driver that has data from two separate tables. One table contains detail about what the driver is picking up the other table contains data about the loading site, tank number & directions. I have omitted some fields from the records that are unimportant for the example. There is a field in each table that is the joining record. This is a project involving crude oil pickups.
Here are examples of the table:
_ticket

ticketnumber

wellid

date

product

operator
_well

wellid

tanknumber

directions
When _ticket.welld = _well.wellid
On The report I want:
_ticket.ticketnumber

_ticket.wellid

_ticket.date

_ticket.product

_ticket.product

_ticket.operator

_well.tanknumber

_well.directions
As you can see the well Id# is in each table.
Please, what should my SQL Query look like?

Alexey admin 9/17/2007

Hi,
here is the query you need:

select

_ticket.ticketnumber,

_ticket.wellid,

_ticket.date,

_ticket.product,

_ticket.product,

_ticket.operator,

_well.tanknumber,

_well.directions

from _ticket

inner join _wells on _ticket.wellid = _well.wellid


Here are some SQL tutorials where you can learn JOIN clause.

http://www.webcheatsheet.com/sql/interactive_sql_tutorial/

http://www.w3schools.com/sql/sql_join.asp

D
dilbertbert author 9/26/2007

That worked PERFECTLY!!!
Thank you very very much!!!