Change Page:
< 12 | Showing page 2 of 2, messages 21 to 26 of 26
gwilym
-
Total Posts
:
3126
-
Reward points
:
6234
- Joined: 25/10/2004
-
Status: offline
- Read my TROG
|
Re:SQL statement issue
31 January 2012 11:44
( permalink)
OK, i might be completely wrong now, but try separating them within the same script, but giving them individual identities. Then at the end of the query, join the 2 parts together using the join you want to. So in essence you have 3 individual queries within the same script. Where I think you're going wrong is trying to include the (SELECT orderid, op.ordprodname, op.ordprodid, SUM(op.ordprodqty) AS qty FROM isc_orders o JOIN isc_order_products op on op.orderprodid=o.orderid WHERE orddate BETWEEN 1271853079 AND 1272637707 GROUP BY op.ordprodid) AS qty, part as a sub query.
Official MaxiRAW Board Representative High-quality, tested performance nutrition. Quality assurance & value guaranteed... www.maxiraw.com Twitter: @MaxiRAW Tag: #Rawdedication
|
|
|
|
Tony Barnes
-
Total Posts
:
17383
-
Reward points
:
6637
- Joined: 07/10/2004
- Location: Leeds
-
Status: offline
- Read my TROG
|
Re:SQL statement issue
31 January 2012 12:03
( permalink)
Yep, defo that bit as a sub query that is cocking it up! Can't figure out how to join them as seperate ones though... Bah, will leave for a bit, other stuff to do!! Ta for input so far
|
|
|
|
gwilym
-
Total Posts
:
3126
-
Reward points
:
6234
- Joined: 25/10/2004
-
Status: offline
- Read my TROG
|
Re:SQL statement issue
31 January 2012 13:05
( permalink)
No worries man. Give us an update when you've sorted it, would be interested to see the solution.
Official MaxiRAW Board Representative High-quality, tested performance nutrition. Quality assurance & value guaranteed... www.maxiraw.com Twitter: @MaxiRAW Tag: #Rawdedication
|
|
|
|
Tony Barnes
-
Total Posts
:
17383
-
Reward points
:
6637
- Joined: 07/10/2004
- Location: Leeds
-
Status: offline
- Read my TROG
|
Re:SQL statement issue
31 January 2012 14:41
( permalink)
lol, you might be waiting a while..!!
|
|
|
|
M1ST
-
Total Posts
:
231
-
Reward points
:
2581
- Joined: 19/08/2009
-
Status: offline
- Read my TROG
|
Re:SQL statement issue
31 January 2012 21:19
( permalink)
Definately go for a JOIN rather than subquery. You'll get a much better query plan too. What does the estimated query plan show? If it's SQL 2008 R2 you may get a useful query optimsation tip...
|
|
|
|
mcsdan
-
Total Posts
:
192
-
Reward points
:
2385
- Joined: 11/06/2009
- Location: somewhere in Essex
-
Status: offline
- Read my TROG
|
Re:SQL statement issue
01 February 2012 15:55
( permalink)
(SELECT orderid, op.ordprodname, op.ordprodid, SUM(op.ordprodqty) AS qty FROM isc_orders o JOIN isc_order_products op on op.orderprodid=o.orderid WHERE orddate BETWEEN 1271853079 AND 1272637707 GROUP BY op.ordprodid) AS qty Shouldn't this have all non aggregate fields in the group clause:- group by orderid,op.ordprodname, op.ordprodid ie (SELECT orderid, op.ordprodname, op.ordprodid, SUM(op.ordprodqty) AS qty FROM isc_orders o JOIN isc_order_products op on op.orderprodid=o.orderid WHERE orddate BETWEEN 1271853079 AND 1272637707 group by orderid,op.ordprodname, op.ordprodid) AS qty
<message edited by mcsdan on 01 February 2012 16:04>
|
|
|
|