dbTalk Databases Forums  

Re: Building a report from two tables...

comp.databases.mysql comp.databases.mysql


Discuss Re: Building a report from two tables... in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
SpreadTooThin
 
Posts: n/a

Default Re: Building a report from two tables... - 02-07-2011 , 06:55 PM






Correction to the sql statement....

Select Customer_Name, Customer_Telephone, Order_Amount from Orders
where Order_Amount > 100

Reply With Quote
  #2  
Old   
SpreadTooThin
 
Posts: n/a

Default Re: Building a report from two tables... - 02-07-2011 , 07:02 PM






On Feb 7, 5:55*pm, SpreadTooThin <bjobrie... (AT) gmail (DOT) com> wrote:
Quote:
Correction to the sql statement....

Select Customer_Name, Customer_Telephone, Order_Amount from Orders
where Order_Amount > 100
Is it really this simple?

SELECT table1.column1, table2.column2 FROM table1, table2 WHERE
table1.column1 = table2.column1;

Really? I would have thought there needed to be nested select
statements...
Is this an oversimplification?
Here the WHERE statement is a comparison between the two tables?
What happens when the WHERE statement is only on one or the other?

Reply With Quote
  #3  
Old   
SpreadTooThin
 
Posts: n/a

Default Re: Building a report from two tables... - 02-07-2011 , 07:16 PM



On Feb 7, 6:02*pm, SpreadTooThin <bjobrie... (AT) gmail (DOT) com> wrote:
Quote:
On Feb 7, 5:55*pm, SpreadTooThin <bjobrie... (AT) gmail (DOT) com> wrote:

Correction to the sql statement....

Select Customer_Name, Customer_Telephone, Order_Amount from Orders
where Order_Amount > 100

Is it really this simple?

SELECT table1.column1, table2.column2 FROM table1, table2 WHERE
table1.column1 = table2.column1;

Really? *I would have thought there needed to be nested select
statements...
Is this an oversimplification?
Here the WHERE statement is a comparison between the two tables?
What happens when the WHERE statement is only on one or the other?
Pardon me if I talk to myself while I wait for answers...

select Customer.Customer_Name, Customer.Customer_Telephone,
Orders.Order_Amount from Customer, Orders where Orders.Order_amount <
100

What doesn't seem right here is that shouldn't there be two selects
here? an inner and an outter?

This being the inner select
Select Customer_Name, Customer_Telephone, Customer_ID from Customer
and this being the outer select
Select Customer_ID, Order_Amount from Orders where Order_Amount > 100

Reply With Quote
  #4  
Old   
Jerry Stuckle
 
Posts: n/a

Default Re: Building a report from two tables... - 02-07-2011 , 08:05 PM



On 2/7/2011 8:16 PM, SpreadTooThin wrote:
Quote:
On Feb 7, 6:02 pm, SpreadTooThin<bjobrie... (AT) gmail (DOT) com> wrote:
On Feb 7, 5:55 pm, SpreadTooThin<bjobrie... (AT) gmail (DOT) com> wrote:

Correction to the sql statement....

Select Customer_Name, Customer_Telephone, Order_Amount from Orders
where Order_Amount> 100

Is it really this simple?

SELECT table1.column1, table2.column2 FROM table1, table2 WHERE
table1.column1 = table2.column1;

Really? I would have thought there needed to be nested select
statements...
Is this an oversimplification?
Here the WHERE statement is a comparison between the two tables?
What happens when the WHERE statement is only on one or the other?

Pardon me if I talk to myself while I wait for answers...

select Customer.Customer_Name, Customer.Customer_Telephone,
Orders.Order_Amount from Customer, Orders where Orders.Order_amount
100

What doesn't seem right here is that shouldn't there be two selects
here? an inner and an outter?

This being the inner select
Select Customer_Name, Customer_Telephone, Customer_ID from Customer
and this being the outer select
Select Customer_ID, Order_Amount from Orders where Order_Amount> 100


No, you don't need two SELECT statements. That's what relational
databases are all about - relationships between entities in different
tables.

Your WHERE clause will work, but it's much better to use a JOIN. It is
more flexible and separates the selection criteria from the relationship
criteria, i.e.

SELECT c.Customer-Name, c.Customer_Telephone, c.Customer_ID,
o.Order_Amount
FROM customer c
JOIN Order o on c.Customer_ID = o.Customer_id
WHERE o.Order_Amount > 100

Note I use aliases ('c' and 'o'). I always use them when joining tables
for clarity (and to eliminate errors where two tables contain the same
column name, as Customer_ID appears here).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex (AT) attglobal (DOT) net
==================

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.