Hi Guys ,

i have faced a sql command problem. That is currently i have 2 different table

a) Select ID, Name from Table1 where ID >=1 and ID ID <=3
  ID      |    Name
  1       |     Alan
  2       |     Amy
  3       |    Andrew
b) Select ID,Sum(Points) as [Total] from Table2 where  
ID >=1 and ID <=3
[No Record From ID > =1 until ID <=3]

My question is how to combine both queries so i can make my table result at below:
ID | Name | Total
1 | Alan | 0
2 | Amy | 0
3 | Andrew | 0

Recommended Answers

All 5 Replies

I think this is what you want. Hard to say without the table structures or an accurate description.

Select ID, Name,
(
  Select Sum(Points)
  From Table2
  Where Table2.ID = Table1.ID
) As Total
From Table1
Where ID >= 1 and ID <= 3
Order By ID

I think this is what you want. Hard to say without the table structures or an accurate description.

Select ID, Name,
(
  Select Sum(Points)
  From Table2
  Where Table2.ID = Table1.ID
) As Total
From Table1
Where ID >= 1 and ID <= 3
Order By ID

Thanks for your helping. I get your means and i can get what i want. Thank you very much

Please mark this thread as solved if you are happy with the solution.

Thanks

1.

SELECT pos_cashreceiptdetail.LocationCode,pos_cashreceiptpayment.TerminalCode,pos_cashreceiptpayment.ReceiptDate,
pos_cashreceiptdetail.Description,pos_cashreceiptpayment.ReceiptNo,SUM(TotalCost),SUM(TotalPrice)
FROM pos_cashreceiptdetail,pos_cashreceiptpayment
WHERE pos_cashreceiptdetail.Description LIKE 'Raw%'
AND pos_cashreceiptdetail.LocationCode = pos_cashreceiptpayment.LocationCode
AND pos_cashreceiptdetail.ReceiptDate = pos_cashreceiptpayment.ReceiptDate
AND pos_cashreceiptdetail.ReceiptDate BETWEEN '2010-10-06' AND '2010-10-20'
GROUP BY pos_cashreceiptpayment.ReceiptDate,pos_cashreceiptdetail.ReceiptNo

2.

SELECT pos_cashreceiptdetail.LocationCode,pos_cashreceiptpayment.TerminalCode,pos_cashreceiptpayment.ReceiptDate,
pos_cashreceiptdetail.ShortDescription,pos_cashreceiptpayment.ReceiptNo,SUM(Totalprice)
FROM pos_cashreceiptdetail,pos_cashreceiptpayment
WHERE pos_cashreceiptdetail.ShortDescription LIKE 'Food Stall%'
AND pos_cashreceiptdetail.ReceiptDate = pos_cashreceiptpayment.ReceiptDate
AND pos_cashreceiptdetail.ReceiptNo = pos_cashreceiptpayment.ReceiptNo
AND pos_cashreceiptdetail.ReceiptDate BETWEEN '2010-10-06' AND '2010-10-20'
GROUP BY pos_cashreceiptpayment.ReceiptDate

This my problem. How to combine this query? This query come from one same existing table. Please help me then...

Thanks in advance yeah.. cheers

Hi a have 4 tables

Table A
ID | Data 1
---------------
1 | A

Table B
ID | Data 2
-----------------
1 | B
1 | C

Table C
ID | Data 3
----------------
1 | D
1 | E
1 | F

Table D
ID | Data 4
----------------
1 | G
1 | H

I want to have this result

Table Result
ID | Data 1 | Data 2 | Data 3 | Data 4
-----------------------------------------------------------------------
1 | A | B | D | G
| | C | E | H
| | | F |

Pls help.....

commented: Don't hijack dead threads -2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.