How do I select attributes in a relational database where I need to validate multiple attributes?

I have a relational database and I have a table like this

         person1           age       job           gender
        +++++++++++++++++++++++++++++++++++++++++++++++++
         p1                22        abc           m
         p2                42        bng           f
         p3                38        xyz           m

      

I have to select the person in which he should have age = '42', job = 'bng' and gender = 'f'

I used Like this

Select person1.*
where person1.age='42' and person1.job='bng' and person1.gender='f';

      

But I am not getting anything. So how do you select a row?

+3


source to share


2 answers


You are missing a sentence FROM

, and string literals must be in ''

double quotes instead. If age

it is a numeric data type, remove the quotes around it if not use ''

. Something like:

Select person1.*
FROM person1
where person1.age    = 42 
  and person1.job    = 'bng' 
  and person1.gender = 'f';

      

Demo SQL Fiddle .



This should give you the line:

| PERSON1 | AGE | JOB | GENDER |
--------------------------------
|      p2 |  42 | bng |      f |

      

+2


source


you are missing From

in your request. If person1 is not your table name then use like



Select tablename(whatever your table name).* from tablename(whatever your table name) where age=42 and job='bng' and gender='f';

+1


source







All Articles