last day (16 days later) » 

11:19 PM
1
A: SQL Server: get all rows where ProductID occurs

Zaynul Abadin Tuhinit seems you need just in select t.ID ,t.ProductID,t.quantity from your_table t where t.ID in ( select ID from your_table t1 where t1.PRODUCT_ID =19) From your comments it seems to me you need subquery with in check this fiddle link https://dbfiddle.uk/?rdbms=sqlserver_2017&fiddle=dfd72f991...

 
sorry but it's impossible, i'm working on a 50mil records db and i don't know where the ProductID i'm looking for is in
 
@DanielF it full fill your sample output condition
 
@DanielF - a) your question is very vague, for all we know there are just the 10 records you have in your question b) you did not include your RDBMs (recommended when you select the sql tag) c) You should include the schema with data, see this previous question.
 
@Zaynul it just shows me all IDs with 1 2 or 8 but i need the whole product set
 
@DanielF it will shows all columns
 
11:19 PM
@Igor i updated the description
@ZaynulAbadinTuhin you dont understand what i need. I don't search for the ID, i don't know the ID. I'm looking for the ProductID and i need all information of the ID
 
@DanielF describe your logic otherwise how anyone can know your logic
 
@ZaynulAbadinTuhin i, for example, search for Product ID = 9 and i want to have a result set which contains ALL ProductIDs, qty and amount for the ID, where ProductID = 9 is occuring
 
@DanielF then put where condition productId=9
@DanielF lets say ProductID =11 then how many rows will return as a output?
 
@ZaynulAbadinTuhin watch the output result set, you don't understand what i need...
 
@DanielF in the example that you have provided what was the Product ID that you used that will generate this output?
 
11:19 PM
@KarthikGanesan ProductID is 19, occurs in ID 1, 2 and 3
 
@DanielF you mean 1,2 and 8
 
@DanielF answer updated
@DanielF select t.ID ,t.ProductID,t.quantity from your_table where t.ID in ( select ID from your_table where t.PRODUCT_ID =19) check this query
 
doesn't work, output is only the searched ProductID not the whole ID set like i mentioned in my post
 
@DanielF it must be return all that you mentioned in your comments
@DanielF could you plz create your table here in fiddle dbfiddle.uk/…
@DanielF dbfiddle.uk/… check this link
@DanielF does it works?
 
it only gives me 1 ID per each ProductID... try it out by yourself: db-fiddle.com/f/hkp5Sy2Y8VFaj86Ft3hFdZ/0
 
11:19 PM
@DanielF you didn't follow my code you did like yours see it returns all
@DanielF SELECT t.ID, t.ProductID, t.quantity FROM test t WHERE t.ID IN (SELECT t.ID FROM test t WHERE t.ProductID = '19')
@DanielF do you have any more argument?
@DanielF does it works
 

  last day (16 days later) »