Click here to Skip to main content
15,665,276 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a purchase order tablepo and there are many multiple PO and Its item list and i want to show in a page just single Purchase number and single from ware house to warehouse


Purchase_order	From_warehouse
9211	Hyderabad Station Roard-HSR
9211	Hyderabad Station Roard-HSR
9211	Hyderabad Station Roard-HSR
9211	Hyderabad Station Roard-HSR
9211	Hyderabad Station Roard-HSR
9211	Hyderabad Station Roard-HSR
123	Hyderabad Canttoment-HCT
123	Hyderabad Canttoment-HCT


and i want result query
Purchase_order	From_warehouse
9211	Hyderabad Station Roard-HSR
123	Hyderabad Canttoment-HCT


What I have tried:

and i want result query 
<pre>Purchase_order	From_warehouse
9211	Hyderabad Station Roard-HSR
123	Hyderabad Canttoment-HCT
Posted
Updated 5-Sep-19 10:57am
Comments
phil.o 5-Sep-19 16:03pm    
You misformed the "What I have tried" part; you are supposed to detail what searches you have performed, and the code you wrote from these that is giving you some troubles.
Please use the Improve question widget which appears on hovering your question, and try to respect the posting guidelines of this forum.
irfanansari 6-Sep-19 12:43pm    
you always have negative mind set that why you take wrong to persons not ablity you have to solve help but just creatisies person open your eyes and see bellow a good man good person reply and solved my issue

Another option is to use DISTINCT.

SQL
SELECT DISTINCT Purchase_order,	From_warehouse
FROM YourTable


This gives you unique records and in my opinion is better than GROUP BY because it is more clear as to your intent.
 
Share this answer
 
v2
Comments
irfanansari 6-Sep-19 13:04pm    
sir thanks a lot for help but there is a problem in this if first colum purchase order and second order same then it shows single reocrd but it is not works when purchase order colum and from warehouse diffrents then it is show all records not single as see bellow
Purchase_order, From_warehouse
003 Hyderabad Station Roard-HSR
004 Hyderabad Station Roard-HSR
007 Hyderabad Canttoment-HCT
007 Hyderabad Station Roard-HSR
008 Hyderabad Station Roard-HSR
123 Hyderabad Station Roard-HSR
786 Hyderabad Canttoment-HCT
9211 Hyderabad Canttoment-HCT
9211 Hyderabad Station Roard-HSR

please sir

i want just single actually if you guide me more then its good i am new in this i am created a table in this i add there many times inserts all fields as date purchase order number from ware house and to ware house
ZurdoDev 6-Sep-19 13:24pm    
I do not understand what you are asking. Given the data you just shared, what would your expected output be?
irfanansari 6-Sep-19 13:25pm    
sir this is querry i search from net and its works but not exact as i want
and i just want to learn mean expalin for me if you can

DECLARE @txtitemname VARCHAR(8000)
SELECT @txtitemname = COALESCE(@txtitemname + ', ', '') + txtitemname FROM tblpo
SELECT distinct txttrannumber, @txtitemname AS Transation_number FROM tblpo
ZurdoDev 6-Sep-19 13:58pm    
You are not being clear on what you want.
irfanansari 7-Sep-19 9:24am    
sir actually this is query i found on internet for get single record can you just explain it for me for understanding

DECLARE @txtitemname VARCHAR(8000)
SELECT @txtitemname = COALESCE(@txtitemname + ', ', '') + txtitemname FROM tblpo
SELECT distinct txttrannumber, @txtitemname AS Transation_number FROM tblpo
Try:
SQL
SELECT Purchase_order, From_warehouse
FROM MyTable
GROUP BY Purchase_order, From_warehouse
 
Share this answer
 
Comments
irfanansari 6-Sep-19 13:11pm    
sir thanks a lot for help but there is a problem in this if first colum purchase order and second order same then it shows single reocrd but it is not works when purchase order colum and from warehouse diffrents then it is show all records not single as see bellow
Purchase_order, From_warehouse
003 Hyderabad Station Roard-HSR
004 Hyderabad Station Roard-HSR
007 Hyderabad Canttoment-HCT
007 Hyderabad Station Roard-HSR
008 Hyderabad Station Roard-HSR
123 Hyderabad Station Roard-HSR
786 Hyderabad Canttoment-HCT
9211 Hyderabad Canttoment-HCT
9211 Hyderabad Station Roard-HSR

please sir

i want just single actually if you guide me more then its good i am new in this i am created a table in this i add there many times inserts all fields as date purchase order number from ware house and to ware house

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900