Multiple "or" in select

74 views Asked by At

I have one table, similar to this

NAME1   NAME2   LASTNAME1   LASTNAME2   Nationalid  etc..
_____________________________________________________________________
ALISON  NULL    LAWRENCE    NULL        6545677     ....
CARLOS  NULL    LOPEZ       RECINOS     NUL         ....
MEL     ANDREA  CHEW        PHELPS      743674      ....

Well this table have 3,000 or more rows, are very much names and in my page i have 4 textbox and one button search when you put a name i do a select and after show the more information of that name but in my select I have a problem I do this:

SELECT * FROM resumen WHERE NAME1 = 'CARLOS' and NAME2 = ''
or NAME2 IS NULL and LASTNAME = 'LOPEZ' AND LASTNAME2 = 'RECINOS' or LASTNAME2 IS NULL

because is probably the NAME2 and LASTNAME2 IS NULL but when I search fro example

CARLOS NULL LOPEZ RECINOS

I receive:

ALISON     NULL     LAWRENCE    NULL      6545677  ....
CARLOS     NULL     LOPEZ       RECINOS   NULL     ....

in this example only have 1 row more but in the real table I have 1,000 rows..
I don't know how I search with 2 or is null

2

There are 2 answers

0
Derek On

I think you want some brackets:

 SELECT * 
 FROM resumen
 WHERE NAME1 = 'CARLOS' and 
       (NAME2 = '' or NAME2 IS NULL) and 
       LASTNAME = 'LOPEZ' AND
       (LASTNAME2 = 'RECINOS' or LASTNAME2 IS NULL)
0
AudioBubble On
 SELECT * 
 FROM resumen
 WHERE NAME1 = 'CARLOS' and 
       (NAME2 = '' or NAME2 IS NULL) and 
       LASTNAME = 'LOPEZ' AND
       (LASTNAME2 = 'RECINOS' or LASTNAME2 IS NULL)