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:
"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
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:
"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