error in MYSQL query

2

I'm doing a query which returns empty values when that column has data with those values, this is the query.

select * from 'clase' 
where 'fk_id_familia' = 3 
and 'fk_id_familia' = 6 
and 'fk_id_familia' = 2

And these are the data that the table has:

$clase = array(
      array('id_clase' => '25','clase' => 'Equipo Veterinario','fk_id_familia' => '1'),
      array('id_clase' => '26','clase' => 'Vestuario Para Pacientes','fk_id_familia' => '2'),
      array('id_clase' => '27','clase' => 'Agendas y Accesorios','fk_id_familia' => '3'),
      array('id_clase' => '28','clase' => 'Suministros De Escritorio','fk_id_familia' => '4'),
      array('id_clase' => '29','clase' => 'Muebles Para La Clinica Dental','fk_id_familia' => '5'),
      array('id_clase' => '30','clase' => 'Formulas y Productos Para Apoyo Nutritivo','fk_id_familia' => '6'),
      array('id_clase' => '31','clase' => 'Espejos Quirurjicos','fk_id_familia' => '7')
    );

And this is the structure of the table:

CREATE TABLE 'clase' (
      'id_clase' int(11) NOT NULL,
      'clase' varchar(500) NOT NULL,
      'fk_id_familia' int(11) NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;'
    
asked by Andersson Meza Andrade 27.10.2017 в 18:23
source

2 answers

2

The error is in your query, you are literally saying:

"Bring me the elements that have fk_id_familia = 1 And fk_id_familia = 2 And fk_id_familia = 3", that is, you are looking for an item that has the 3 values in the same field which in your case is not given.

You must change your query for this:

select * from 'clase' where 'fk_id_familia' = 3 or 'fk_id_familia' = 6 or 'fk_id_familia' = 2

Or you could use an IN

select * from 'clase' where 'fk_id_familia' in (3, 6, 2)
    
answered by 27.10.2017 / 18:41
source
1

use an IN like this:

select * from clase where fk_id_familia in (2,3,6);
    
answered by 29.10.2017 в 04:05