|
-
May 24th, 2006, 05:08 PM
#1
Thread Starter
Stuck in the 80s
Sql + Distinct + Inner Join + Eek
I'm having trouble trying to figure out how to run a query. I want to only select distinct order_ids, but list all columns. I know I have to use a GROUP BY s.order_id, but I can't figure out where to put it. I get an error everywhere I go. Any ideas?
Code:
SELECT DISTINCT( s.order_id ), * FROM schedule AS s
INNER JOIN schedule_detail AS sd ON s.s_id = sd.s_id
WHERE sd.invoice_id = 0 AND s.shipped_quantity = s.quantity
AND s.quantity > 0
FYI, using Postgres.
-
May 24th, 2006, 05:13 PM
#2
Re: Sql + Distinct + Inner Join + Eek
This doesn;'t make any sense to me - you want a single ORDER ID but all the columns associated with that ORDER ID.
Is there more then one row with the same ORDER ID in the details table? Which row's data would you want to show?
-
May 29th, 2006, 08:33 PM
#3
Thread Starter
Stuck in the 80s
Re: Sql + Distinct + Inner Join + Eek
I ended up taking a different route with this. In the schedule table (shipment schedule), the order id may be present more than once, as an order may have multiple parcels, so yes. What I wanted to do was to grab only unique order ids, but at the same time return all fields for the row, but only have DISTINCT applied to the order id.
I just ended up returning all order ids then pulling associated information in a seperate query (from a completely different table, even). This was mostly because the scope of the projet changed.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|