Home > Blockchain >  SQL; SELECT, WHERE AND OR
SQL; SELECT, WHERE AND OR

Time:08-19

I need a Query which would return results like this :

SELECT * FROM MyTable WHERE IDtable1 = IDtable2 AND (Column1 like "THIS" OR Column1 Like "THAT")

I have tried this:

SELECT [SALARIE_nom] & " " & [SALARIE_prenom] & " (" & [SALARIE_NNI] & ")" AS Salarié,
T_SALARIE_EMPLOI.SALARIE_EMPLOI_emploi_identifiant, 
T_STATUT_EMPLOI.STATUT_EMPLOI_statut

FROM 
(T_STATUT_EMPLOI INNER JOIN T_SALARIE_EMPLOI ON T_STATUT_EMPLOI.STATUT_EMPLOI_id = T_SALARIE_EMPLOI.SALARIE_EMPLOI_statut_id) LEFT JOIN R_Select_Salarie ON T_SALARIE_EMPLOI.SALARIE_EMPLOI_salarie_nni = R_Select_Salarie.SALARIE_NNI

WHERE 
(((T_SALARIE_EMPLOI.SALARIE_EMPLOI_emploi_identifiant)=[Formulaires]![F_COMOB]![ACTION_identifiant_emploi]) 
AND 
((T_STATUT_EMPLOI.STATUT_EMPLOI_statut) Like "*valid*")) 
OR 
(((T_STATUT_EMPLOI.STATUT_EMPLOI_statut) Like "*décidé*"));

It works as I want only when I don't put the :

OR 
    (((T_STATUT_EMPLOI.STATUT_EMPLOI_statut) Like "*décidé*"))

When I try this (Regroup the OR part)

WHERE 
T_SALARIE_EMPLOI.SALARIE_EMPLOI_emploi_identifiant=[Formulaires]![F_COMOB]![ACTION_identifiant_emploi]
AND 
(T_STATUT_EMPLOI.STATUT_EMPLOI_statut Like "*valid*"
OR 
T_STATUT_EMPLOI.STATUT_EMPLOI_statut Like "*décidé*");

No results are shown.

And when I try This

WHERE 
(((T_SALARIE_EMPLOI.SALARIE_EMPLOI_emploi_identifiant)=[Formulaires]![F_COMOB]![ACTION_identifiant_emploi]) 
AND 
((T_STATUT_EMPLOI.STATUT_EMPLOI_statut) Like "*valid*")) 
OR 
(((T_STATUT_EMPLOI.STATUT_EMPLOI_statut) Like "*décidé*"));

It's seem like it didn't take this

WHERE 
    (((T_SALARIE_EMPLOI.SALARIE_EMPLOI_emploi_identifiant)=[Formulaires]![F_COMOB]![ACTION_identifiant_emploi]) 

into consideration

CodePudding user response:

How about adding opening bracket after the AND in the Where condition and closing bracket before semicolon(;)

Does it return desired result?

SELECT [SALARIE_nom] & " " & [SALARIE_prenom] & " (" & [SALARIE_NNI] & ")" AS Salarié,
T_SALARIE_EMPLOI.SALARIE_EMPLOI_emploi_identifiant, 
T_STATUT_EMPLOI.STATUT_EMPLOI_statut

FROM 
(T_STATUT_EMPLOI INNER JOIN T_SALARIE_EMPLOI ON T_STATUT_EMPLOI.STATUT_EMPLOI_id = T_SALARIE_EMPLOI.SALARIE_EMPLOI_statut_id) LEFT JOIN R_Select_Salarie ON T_SALARIE_EMPLOI.SALARIE_EMPLOI_salarie_nni = R_Select_Salarie.SALARIE_NNI

WHERE 
T_SALARIE_EMPLOI.SALARIE_EMPLOI_emploi_identifiant=[Formulaires]![F_COMOB]![ACTION_identifiant_emploi]
AND 
(T_STATUT_EMPLOI.STATUT_EMPLOI_statut Like "*valid*"
OR 
T_STATUT_EMPLOI.STATUT_EMPLOI_statut Like "*décidé*");
  •  Tags:  
  • sql
  • Related