Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying multiple values

I'm trying to filter by multiple values however I can't seem to get an and clause to work (e.g. filter1 and filter 2 ... etc.):

Show me snapshots where the database name is 'testing'

aws rds describe-db-snapshots --include-shared --query 'DBSnapshots[?DBInstanceIdentifier==`testing`].{DBNAME:DBInstanceIdentifier,SNAPSHOT:DBSnapshotIdentifier}'
[
    {
        "SNAPSHOT": "test1",
        "DBNAME": "testing"
    },
    {
        "SNAPSHOT": "test2",
        "DBNAME": "testing"
    },
    {
        "SNAPSHOT": "test3",
        "DBNAME": "testing"
    },
    {
        "SNAPSHOT": "test4",
        "DBNAME": "testing"
    }
]

Show me snapshots named 'test1'

$ aws rds describe-db-snapshots --include-shared --query 'DBSnapshots[?DBSnapshotIdentifier==`test1`].{DBNAME:DBInstanceIdentifier,SNAPSHOT:DBSnapshotIdentifier}'
[
    {
        "SNAPSHOT": "test1",
        "DBNAME": "testing"
    },
        {
        "SNAPSHOT": "test1",
        "DBNAME": "testing2"
    }
]

Show me snapshots from the database testing that are named test1

aws rds describe-db-snapshots --include-shared --query 'DBSnapshots[?DBInstanceIdentifier==`testing`][?DBSnapshotIdentifier==`test1`].{DBNAME:DBInstanceIdentifier,SNAPSHOT:DBSnapshotIdentifier}'
[]

How can this be achieved?

like image 915
bob dylan Avatar asked Nov 07 '17 16:11

bob dylan


People also ask

How do I select multiple values in SQL query?

To select multiple values, you can use where clause with OR and IN operator.

How do I query multiple values from the same column in SQL?

Note – Use of IN for matching multiple values i.e. TOYOTA and HONDA in the same column i.e. COMPANY. Syntax: SELECT * FROM TABLE_NAME WHERE COLUMN_NAME IN (MATCHING_VALUE1,MATCHING_VALUE2);

What is like %% in SQL?

The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. There are two wildcards often used in conjunction with the LIKE operator: The percent sign (%) represents zero, one, or multiple characters. The underscore sign (_) represents one, single character.


1 Answers

You need to work with the AND expression so something like this will make the trick

$ aws rds describe-db-snapshots --include-shared \
--query 'DBSnapshots[?(DBInstanceIdentifier==`testing` && DBSnapshotIdentifier==`test1`)].{DBNAME:DBInstanceIdentifier,SNAPSHOT:DBSnapshotIdentifier}'
like image 196
Frederic Henri Avatar answered Nov 02 '22 05:11

Frederic Henri