1

I have to find all those records for which I provide ids, so here is my query

SELECT * FROM `inf_company` where id IN(25523,25511,25448,28094,25243.....)

I provide 500 Ids in above query but it give me 200 records. I want to find rest of missing 300 records.

I want to see all those ids in my list which is not shown in result. How could be the query for that?

12
  • Is it problem in PMA or your project? Сheck the settings. Try add LIMIT 0, 500 Commented Aug 26, 2014 at 7:22
  • 2
    Are you sure the other 300 ids exists in your table? Commented Aug 26, 2014 at 7:24
  • 2
    Build a (temporary) table of the desired ids and join it on to this table. Commented Aug 26, 2014 at 7:25
  • I want to see all those in my list Commented Aug 26, 2014 at 7:27
  • 1
    Where does that list of ids come from in the first place? I doubt you have written them manually, right? If they come from another table, can't you LEFT JOIN from there? (Oh... and please edit the title... as it is it's absolutely meaningless) Commented Aug 26, 2014 at 7:36

1 Answer 1

1

You could write a union for the id fields and left outer join to get actual result:

select id
,      case
       when i1.id is not null
       then 'EXISTING'
       else 'NON-EXISTING'
       end
       status
from   ( select 25523 id union select 25511 union select 25448 /* etc, etc */ ) x
left
outer
join   inf_company i1
on     i1.id = x.id

You could also put the ids in a temporary table as suggested by Strawberry. That will prevent the long list of union on id.

Sign up to request clarification or add additional context in comments.

6 Comments

you asked me to write select 25523 id union select 25511 manually?should i write all 500 ids here?
Yes, just as in your current query, or preferably insert them in a temporary table. In this cases Excel may come in handy to fabricate the query.
@user3244721: Did this solve your issue? Need more help?
I am doing it manually in excel...by query it is not possible
What is your problem with this query?
|

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.