1

I have a comma separated numbers like '46,95,44' which is the output obtained from GROUP_CONCAT

select GROUP_CONCAT (prodid) from tablename where condition;

I want to convert this to integer such that i can use this as the input to the "in" operation

select * from table2 where prodid in 
(
   select GROUP_CONCAT (prodid) from tablename where condition
);

The above query results only base on the first number in the comma separated list . How to convert the list in to integer

output :  46,95,44 

1 Answer 1

3

Remove the group_concat

select * from table2 
where prodid in 
(
  select prodid
  from tablename
  where condition
);

group_concat produces a single string with ids, but you need seperate values for the IN clause.

With group_concat your query compiles to

select * from table2 
where prodid in ('46,95,44');

but you need

select * from table2 
where prodid in ('46','95','44');
Sign up to request clarification or add additional context in comments.

4 Comments

if the "select prodid from tablename where condition" returns multiple rows it will pop an error.
Then the error comes from something else. IN has no problem with multiple records. What is the complete error message?
@juergend your solution is perfect no doubt, but query taking too much of time
@Kuldeep: Then you can ask a question on Stack Overflow about it including table definition, example data, the query you tried and indexes you have on your tables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.