Forum Moderators: coopster

Message Too Old, No Replies

Need Help combining 2 Tables

         

Gian04

6:59 am on Aug 4, 2007 (gmt 0)

10+ Year Member



table_1

Name ¦ Address ¦ Email Address
Jake TX abc@example.com
Ric OH ric@example.com

table_2

Name ¦ Date ¦ Score
Jake 01/05/07 34
Ric 06/07/07 14
Ric 08/1/07 18
Jake 02/09/07 12
Jake 07/15/07 30

I need a query that will give an output like this (ORDER BY score), please help :

Name ¦ Score
Jake 76
Ric 32

[edited by: Gian04 at 7:03 am (utc) on Aug. 4, 2007]

darrenG

10:16 am on Aug 4, 2007 (gmt 0)

10+ Year Member



select name, score from table_1, table_2 where table_1.name = table_2.name order by score

Gian04

10:37 am on Aug 4, 2007 (gmt 0)

10+ Year Member



Did you read the requirement? Given the example above it will show 5 rows when it should only display 2 rows

This query shows an error :

SELECT table_1.name, sum(table_2.score) AS total_score from table_1, table_2 WHERE table_1.name = table_2.name ORDER by total_score

[edited by: Gian04 at 10:43 am (utc) on Aug. 4, 2007]

darrenG

11:52 am on Aug 4, 2007 (gmt 0)

10+ Year Member



I dont see anywhere in the 'requirement' any mention of summing up the score column. Im not exactly going to total up the score column myself just incase you require it..

You need to specify how the data is sum()'ed - use group by name.

select name, sum(score) as ts from table_1, table_2 where table_1.name = table_2.name group by table_2.name order by ts

[edited by: darrenG at 11:53 am (utc) on Aug. 4, 2007]

Gian04

12:45 pm on Aug 4, 2007 (gmt 0)

10+ Year Member



Read Again, I said:

I need a query that will give an output like this (ORDER BY score), please help :

Name ¦ Score
Jake 76
Ric 32

jatar_k

12:49 pm on Aug 4, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



not really the best way to get any help

how about you share with us what you've tried and where the trouble is

darrenG

5:07 pm on Aug 4, 2007 (gmt 0)

10+ Year Member



Im not quite sure where our wires have become crossed.

When I said:

"You need to specify how the data is sum()'ed - use group by name."

I meant in your SQL query - not to me lol

Add the 'group by name' clause to your query and it should work fine