Originariamente inviato da ipermax87
Si esiste... ma anche non esistesse non vedo dove sarebbe il problema:
potrei usare un SELECT DISTINCT sulla tabella degli acquisti, o sbaglio?
cmq hai idee? io non so più cosa inventarmi...
A mio parere JorTaras non sbaglia quando dice che ti serve
la tabella degli utenti
Se tu fai un SELECT DISTINCT sulla tabella acquisti
ti perdi tutti gli utenti che non hanno mai
acquistato nulla, quindi non compaiono nella tabella acquisti
( potrebbe essere una cosa voluta ma questo lo sai solo te )
__________________________________________________ _______________
__________________________________________________ _______________
__________________________________________________ _______________
__________________________________________________ _______________
Se hai queste 3 tabelle
( i nomi li ho desunti dalle tue 2 query postate )
___ acquirenti
_____ user ______ Testo
___ Prodotti
_____ codprod ___ Testo
___ Acquisti
_____ nome ______ Testo
_____ codprod ___ Testo
Con 2 relazioni
__ acquirenti.user ------> Acquisti.nome
__ Prodotti.codprod -----> Acquisti.codprod
__________________________________________________ ________________
Io farei una prima vista fra acquirenti e Prodotti
che mi restituisce tutti gli user e tutti i codprod
( 5 user e 8 codprod fanno 40 record restituiti )
poi metterei in LEFT JOIN questa prima vista
con la tabella Acquisti filtrando i valori Null
su Acquisti.nome
Poi nidifichi le 2 viste l'una nell'altra
Sei arrivato al risultato
__________________________________________________ _____________
__________________________________________________ _____________
__________________________________________________ _____________
__________________________________________________ _____________
Seguono 2 esempi
( con il SELECT DISTINCT su Acquisti e con la tabella acquirenti )
NON testati perche non ho MySql quindi
poresti avere degli errori di sintassi da correggere
codice:
SELECT
S1.nome,
S1.codprod
FROM
(
SELECT DISTINCT
Acquisti.nome,
Prodotti.codprod
FROM
Acquisti,
Prodotti
) AS S1
LEFT JOIN
Acquisti
ON
(S1.nome = Acquisti.nome)
AND
(S1.codprod = Acquisti.codprod)
WHERE (((Acquisti.nome) Is Null))
;
codice:
SELECT
T1.user,
T1.codprod
FROM
(
SELECT
acquirenti.user,
Prodotti.codprod
FROM
Prodotti,
acquirenti
) AS T1
LEFT JOIN
Acquisti
ON
(T1.codprod = Acquisti.codprod)
AND
(T1.user = Acquisti.nome)
WHERE (((Acquisti.nome) Is Null))
;
Facci sapere