Equal and Not Equal to QBE Operators
Learn to use QBE operators _eq
, and _ne
to
filter specific data from the car racing dataset through simple examples.
Consider a scenario where you would like to fetch the details of a specific
team. You can use the _eq
QBE operator compare if the name is equal to
the specific team's name you are looking for, and fetch details of that exact team:
Example 3-3 _eq
Operator
SELECT JSON_SERIALIZE(data PRETTY) AS data FROM GRAPHQL('
team (
check: {
name: {_eq: "Ferrari"}
}
) {
id: team_id
name
points
}
');
This code would access the table team
, fetches the
id
, name
and points
only for the
team named "Ferrari":
DATA
--------------------------------------------------------------------------------
{
"id" : 302,
"name" : "Ferrari",
"points" : 652
}
1 row selected.
name: "Ferrari"
instead of name: {_eq:
"Ferrari"}
which would still produce the same
output:SELECT JSON_SERIALIZE(data PRETTY) AS data FROM GRAPHQL('
team (
check: {
name: "Ferrari"
}
) {
id: team_id
name
points
}
');
Or you may want to fetch details of the team named "McLaren Mercedes". Further, you would like to find the drivers in the team other than "Oscar Piastri".
Example 3-4 _ne
Operator
SELECT JSON_SERIALIZE(data PRETTY) AS data FROM GRAPHQL('
team (
check: {
name: "McLaren Mercedes"
}
){
id: team_id
name
points
drivers: driver (
check: {
name: {_ne: "Oscar Piastri"}
}
) {
name
points
}
}
');
The example uses two filters, first one to filter the team based on the team's name and second one to identify the driver names which is not equal to "Oscar Piastri" :
DATA
--------------------------------------------------------------------------------
{
"id" : 301,
"name" : "McLaren Mercedes",
"points" : 666,
"drivers" :
[
{
"name" : "Lando Norris",
"points" : 282
}
]
}
1 row selected.