Joomla.it Forum

Non solo Joomla... => Database => : dpmika 11 Feb 2014, 19:21:27

: Query per recupero records con diversi valori nello stesso campo
: dpmika 11 Feb 2014, 19:21:27
Ciao a tutti,


ho un problema a creare una query. 


La mi tabella è formata cosi:


user_id    attributo_id
   1                2
   1                4
   1                5
   2                2
   2                5
   3                1

Adesso non riesco a recuperare per esempio gli user_id che hanno come attributo_id sia il 2 che il 4.

Ho provato a far cosi:

Select * from nometabella where attributo_id ="2" and  attributo_id ="4"

pero facendo cosi mi recupera sia quelli che hanno solo il 2 sia quelli che hanno solo il 4.


Invece ho l'esigenza di recuperare solo gli utenti che hanno entrambi gli attributo_id

qualcuno ha la soluzione? :)

grazie
: Re:Query per recupero records con diversi valori nello stesso campo
: tomtomeight 11 Feb 2014, 21:33:55
Scusa questo non è un forum specifico di linguaggio php o mysql, se non inquadri la richiesta in un contesto di utilizzo  in un estensione joomla, o comunque legata al cms diventa per te più veloce e facile trovare risposta in forum dedicati.
: Re:Query per recupero records con diversi valori nello stesso campo
: otto9due 12 Feb 2014, 09:31:35
Prova a dare un'occhiatina qui.. Se quello che vuoi fare è inerente al mondo joomla..
http://docs.joomla.org/Selecting_data_using_JDatabase (http://docs.joomla.org/Selecting_data_using_JDatabase)
Altrimenti quoto Tom..
: Re:Query per recupero records con diversi valori nello stesso campo
: mmleoni 20 Feb 2014, 15:35:45
in realtà non ho capito niente  :(

:
Select * from nometabella where attributo_id ="2" and  attributo_id ="4"
non deve restituire niente, dato che attributo_id NON può essere contemporaneamente 2 e 4.

semmai:
:
Select * from nometabella where attributo_id ="2" OR  attributo_id ="4"
restituisce che ha attributo_id uguale a 2 oppure a 4.

ciao,
marco