Problem in sql join

%3CLINGO-SUB%20id%3D%22lingo-sub-2419597%22%20slang%3D%22en-US%22%3EProblem%20in%20sql%20join%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2419597%22%20slang%3D%22en-US%22%3E%3CP%3Ethis%20is%20the%20query%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3EWITH%20journal%20as%20(select%20journal_entry.SaleID%20as%20%5Binvoice%20No.%5D%2C%20description%2C%20journal_entry.debit%20as%20%5BDebit%5D%2C%20journal_entry.credit%20as%20%5BPaided%5D%2C%20journal_entry.%5BCustomerID%5D%20as%20%5Bjournal%20Customer%20id%5D%20from%20journal_entry%20)%2C%20SALES%20AS%20(%20SELECT%20sale.saleid%2C%20invoice.InvoiceID%2C%20sale.totalpaid%2C%20item.itemname%20AS%20item%2C%20stock.saleprice%20AS%20SalePice%2C%20invoice.qty%2C%20invoice.StockID%20as%20%5Binvoice%20Stock%20id%5D%2C%20sale.discount%2Cinvoice.saleprice%20AS%20%5Binvoice%20saleprice%5D%2C%20cetegory.catname%20AS%20%5BCateogory%5D%2C%20cetegory.subcat%20AS%20%5BSub%20Catgry%5D%2C%20item.model_number%20AS%20%5BPart%20No.%5D%2C%20invoice.Description%20as%20%5Binvoice%20description%5D%2C%20sale.date%2C%20stock.size%2C%20sale.customerid%20AS%20%5Bcust%20sale%20id%20%5D%2C%20customer.customercontact%2C%20customer.customeraddress%2C%20customer.customerid%2C%20customer.CustomerName%20FROM%20invoice%20JOIN%20item%20ON%20invoice.itemid%20%3D%20item.itemid%20JOIN%20sale%20ON%20invoice.saleid%20%3D%20sale.saleid%20JOIN%20stock%20ON%20invoice.StockID%20%3D%20Stock.StockID%20JOIN%20cetegory%20ON%20item.catid%20%3D%20cetegory.catid%20join%20customer%20on%20sale.CustomerID%20%3D%20customer.CustomerID%20where%20sale.SaleID%20%3D%202%20)%20SELECT%20distinct%20*%20FROM%20journal%20right%20join%20SALES%20on%20journal.%5Binvoice%20No.%5D%20%3D%20SALES.SaleID%20order%20by%20SALES.SaleID%20desc%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3ENow%20here%20i%20have%20some%20problem%201)%20i%20return%20only%20'Asia%20Dryer%20600'%20and%20it%20show%20for%20the%20item%20too.%20i%20want%20to%20skip%20this%20for%20other%20which%20has%20not%20return%202)%20The%20paided%2C%20debit%20and%20discount%20amount%20has%20been%20paid%20according%20to%20one%20saleid%20and%20it%20show%20me%20every%20same%20sale%20id%20i%20want%20when%20the%20sale%20id%20is%20same%20then%20only%20first%20rows%20of%20having%20the%20same%20sale%20id%2C%20these%20(paided%2C%20debit%20and%20discount)%20amount%20show%20and%20for%20else%20it%20should%20be%20zero%20or%20null.%2C%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

this is the query

WITH journal as (select journal_entry.SaleID as [invoice No.], description, journal_entry.debit as [Debit], journal_entry.credit as [Paided], journal_entry.[CustomerID] as [journal Customer id] from journal_entry ), SALES AS ( SELECT sale.saleid, invoice.InvoiceID, sale.totalpaid, item.itemname AS item, stock.saleprice AS SalePice, invoice.qty, invoice.StockID as [invoice Stock id], sale.discount,invoice.saleprice AS [invoice saleprice], cetegory.catname AS [Cateogory], cetegory.subcat AS [Sub Catgry], item.model_number AS [Part No.], invoice.Description as [invoice description], sale.date, stock.size, sale.customerid AS [cust sale id ], customer.customercontact, customer.customeraddress, customer.customerid, customer.CustomerName FROM invoice JOIN item ON invoice.itemid = item.itemid JOIN sale ON invoice.saleid = sale.saleid JOIN stock ON invoice.StockID = Stock.StockID JOIN cetegory ON item.catid = cetegory.catid join customer on sale.CustomerID = customer.CustomerID where sale.SaleID = 2 ) SELECT distinct * FROM journal right join SALES on journal.[invoice No.] = SALES.SaleID order by SALES.SaleID desc;

Now here i have some problem 1) i return only 'Asia Dryer 600' and it show for the item too. i want to skip this for other which has not return 2) The paided, debit and discount amount has been paid according to one saleid and it show me every same sale id i want when the sale id is same then only first rows of having the same sale id, these (paided, debit and discount) amount show and for else it should be zero or null.,

0 Replies