If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > PostgreSQL > SQL Query help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-04-11, 12:04
emotionuk emotionuk is offline
Registered User
 
Join Date: Nov 2011
Posts: 2
SQL Query help

Hello all,

I am a graphic designer and part-time Java programmer, but I am stumped on some SQL stuff.

Basically, I have a Postgre database with some tables. I currently have a query which generates a report from one product category in my Java front end:

Code:
"SELECT " +
                "CLOSEDCASH.HOST, " +
                "CLOSEDCASH.MONEY, " +
                "CLOSEDCASH.DATEEND, " +
                "PRODUCTS.REFERENCE, " +
                "PRODUCTS.NAME, " +
                "SUM(TICKETLINES.UNITS) AS UNITS, " +
                "SUM(TICKETLINES.UNITS * TICKETLINES.PRICE) AS TOTAL " +
                "FROM CATEGORIES, CLOSEDCASH, RECEIPTS, TICKETS, TICKETLINES LEFT OUTER JOIN PRODUCTS ON TICKETLINES.PRODUCT = PRODUCTS.ID " +
                "WHERE CLOSEDCASH.MONEY = RECEIPTS.MONEY AND RECEIPTS.ID = TICKETS.ID AND TICKETS.ID = TICKETLINES.TICKET AND PRODUCTS.CATEGORY = '09b21e95-9cd7-45ac-8f9d-577729991b41' +
                "GROUP BY CLOSEDCASH.HOST, CLOSEDCASH.MONEY, CLOSEDCASH.DATEEND, PRODUCTS.REFERENCE, PRODUCTS.NAME, CATEGORIES.PARENTID " +
                "ORDER BY PRODUCTS.NAME, CLOSEDCASH.HOST, CLOSEDCASH.DATEEND"
I need to make a simple change. The problem at the moment is that the report doesn't include sub-categories of the main category (products.category). There is another table called "Categories" and inside this table there is the "parentid". So, I need to basically say that if the parentid is the same as the main category selected, then show me products from that category too.

I have spent hours trying to figure this out, but I just can't get it to happen. Can anyone help?

Thanks a million,
Christian
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On