Home > Back-end >  Query returns just one record, how to get all records with multiple condition over one column?
Query returns just one record, how to get all records with multiple condition over one column?

Time:12-09

I have the following SQL table:

enter image description here

from which I need to get all those records having role=technical Interviewer and Hr Interviewer.

The SQL query which I wrote for this is:

SELECT * FROM new_user WHERE role='technical Interviewer' OR 'Hr Interviewer';

Output:

enter image description here

But, the problem with this query is, it is returning just one record.

How to fix this issue?

CodePudding user response:

SELECT * FROM new_user WHERE role IN('technical Interviewer', 'Hr Interviewer');

Changing to IN for role will allow you to filter for multiple items without using OR.

CodePudding user response:

I guess you want find the role value is 'technical Interviewer' and 'Hr Interviewer ' you can try the fellow code

SELECT * FROM new_user WHERE role in ('technical Interviewer','Hr Interviewer')

CodePudding user response:

Your table should have data for 'Hr Interviewer'. Your query should be as below.

SELECT * FROM new_user WHERE role='technical Interviewer' OR role='Hr Interviewer'; 

there is another way

SELECT * FROM new_user WHERE role IN ('technical Interviewer','Hr Interviewer');

CodePudding user response:

There is a syntax error in your query.

And are you sure that the name of the roles are correct? ("Hr Interviewer" -> "hr Interviewer")

One other way to write this query is as follows:

SELECT * FROM new_user WHERE LOWER(role)='technical interviewer' OR LOWER(role)='hr interviewer';

Also, are there are any more records that satisfy the condition?

  •  Tags:  
  • sql
  • Related