Previous Next JavaScript must be enabled to correctly display this content

## Logical operators

The operators AND and OR are binary and the NOT operator is unary. The operands of the logical operators are conditional expressions, which must have a type `BOOLEAN`. An empty result from an operand is treated as a false value. If an operand returns NULL( either SQL NULL or JSON NULL), then:

- The AND operator returns false if the other operand returns false; otherwise, it returns NULL.
- The OR operator returns true if the other operand returns true; otherwise, it returns NULL.
- The NOT operator returns NULL.

Example 1: Select the details of the passenger and their bags for a trip with ticket number 1762311547917 or confirmation number KN4D1L.

    SELECT fullName,bag.ticketNo, bag.confNo,
    bag.bagInfo[].tagNum, bag.bagInfo[].routing
    FROM BaggageInfo bag
    WHERE bag.ticketNo=1762311547917 OR bag.confNo="KN4D1L"

Explanation: You fetch the details of passengers satisfying one of the two filter criteria. You do this with the OR clause. You fetch the full name, tag number, ticket number, reservation code, and routing details of passengers satisfying a particular ticket number or a particular reservation code (`confNo`).

Output:

    {"fullName":"Rosalia Triplett","ticketNo":1762311547917,"confNo":"FH7G1W","tagNum":"17657806215913","routing":"JFK/IST/VIE"}
    {"fullName":"Mary Watson","ticketNo":1762340683564,"confNo":"KN4D1L","tagNum":"17657806299833","routing":"YYZ/HKG/BLR"}

Example 2: Select baggage details of passengers traveling between MIA and MEL.

    SELECT fullName, bag.bagInfo[].tagNum, bag.bagInfo[].routing
    FROM BaggageInfo bag
    WHERE bag.bagInfo[].flightLegs[].fltRouteSrc =any "MIA" AND
    bag.bagInfo[].flightLegs[].fltRouteDest=any "MEL"

Explanation: You fetch the details of the passengers traveling between MIA and MEL. Since you need to match 2 conditions here, the flight source and the flight destination, you are using an AND operator. Here the flight source could be the starting point of the flight or any transit airport. Similarly, the flight destination could be a transit airport or a final destination.

Output:

    {"fullName":"Zulema Martindale","tagNum":"17657806288937","routing":"MIA/LAX/MEL"}
    {"fullName":"Adam Phillips","tagNum":"17657806255240","routing":"MIA/LAX/MEL"}
    {"fullName":"Joanne Diaz","tagNum":"17657806292518","routing":"MIA/LAX/MEL"}
    {"fullName":"Zina Christenson","tagNum":"17657806228676","routing":"MIA/LAX/MEL"}

Example 3: Select details of those bags which does not originate from MIA/pass through MIA.

    SELECT fullName, bag.bagInfo[].tagNum, bag.bagInfo[].routing,
    bag.bagInfo[].flightLegs[].fltRouteSrc
    FROM BaggageInfo bag
    WHERE NOT bag.bagInfo[].flightLegs[].fltRouteSrc=any "MIA"

Explanation: You fetch the details of passengers not originating from a particular source. To fetch these details, you are using the NOT operator here. You want to fetch details of bags which did not start/go through MIA.

Output:

    {"fullName":"Kendal Biddle","tagNum":"17657806296887","routing":"JFK/IST/VIE","fltRouteSrc":"JFK"}
    {"fullName":"Lucinda Beckman","tagNum":"17657806240001","routing":"SFO/IST/ATH/JTR","fltRouteSrc":"SFO"}
    {"fullName":"Adelaide Willard","tagNum":"17657806224224","routing":"GRU/ORD/SEA","fltRouteSrc":"GRU"}
    {"fullName":"Raymond Griffin","tagNum":"17657806243578","routing":"MSQ/FRA/HKG","fltRouteSrc":"MSQ"}
    {"fullName":"Elane Lemons","tagNum":"1765780623244","routing":"MXP/CDG/SLC/BZN","fltRouteSrc":"MXP"}
    {"fullName":"Dierdre Amador","tagNum":"17657806240229","routing":"JFK/MAD","fltRouteSrc":"JFK"}
    {"fullName":"Henry Jenkins","tagNum":"17657806216554","routing":"SFO/ORD/FRA","fltRouteSrc":"SFO"}
    {"fullName":"Rosalia Triplett","tagNum":"17657806215913","routing":"JFK/IST/VIE","fltRouteSrc":"JFK"}
    {"fullName":"Lorenzo Phil","tagNum":["17657806240001","17657806340001"],"routing":["SFO/IST/ATH/JTR","SFO/IST/ATH/JTR"],"fltRouteSrc":["SFO","SFO"]}
    {"fullName":"Gerard Greene","tagNum":"1765780626568","routing":"SFO/IST/ATH/JTR","fltRouteSrc":"SFO"}
    {"fullName":"Doris Martin","tagNum":"17657806232501","routing":"BZN/SEA/CDG/MXP","fltRouteSrc":"BZN"}
    {"fullName":"Omar Harvey","tagNum":"17657806234185","routing":"MEL/LAX/MIA","fltRouteSrc":"MEL"}
    {"fullName":"Fallon Clements","tagNum":"17657806255507","routing":"MXP/CDG/SLC/BZN","fltRouteSrc":"MXP"}
    {"fullName":"Lisbeth Wampler","tagNum":"17657806292229","routing":"LAX/TPE/SGN","fltRouteSrc":"LAX"}
    {"fullName":"Teena Colley","tagNum":"17657806255823","routing":"MSQ/FRA/HKG","fltRouteSrc":"MSQ"}
    {"fullName":"Michelle Payne","tagNum":"17657806247861","routing":"SFO/IST/ATH/JTR","fltRouteSrc":"SFO"}
    {"fullName":"Mary Watson","tagNum":"17657806299833","routing":"YYZ/HKG/BLR","fltRouteSrc":"YYZ"}