Documentation Home
MySQL Shell for VS Code


MySQL Shell for VS Code  /  JavaScript  /  DB Notebook: Retrieve Data with SELECT Statements

Pre-General Availability: 2024-10-29

8.2 DB Notebook: Retrieve Data with SELECT Statements

DB Notebook: Basic query returning one row

runSql(
  "SELECT Name as name," +
  "District as district, Population as pop FROM world.city WHERE Name = 'Kabul' ",
  (ResultSetRows) => {
    print(ResultSetRows);
  }
);

The output is:

[
    {
          "name": "Kabul",
          "district": "Kabol",
          "pop": 1780000
    }
]

DB Notebook: Basic query returning multiple rows

runSqlIterative(
  "SELECT Name as n," +
    "Population as p FROM world.city WHERE CountryCode = 'Ven' AND District LIKE 'Bolivar'",
  (IResultSetData) => {
    print(IResultSetData);
  }
);

The output is:

{
  "requestState": {
    "type": "OK",
    "msg": "Full result set consisting of 2 rows transferred."
  },
  "requestId": "25361d27-e80d-4cab-0884-cfe7a75eda56",
  "rows": [
    [
      "Ciudad Guayana",
      663713
    ],
    [
      "Ciudad Bolívar",
      301107
    ]
  ],
  "columns": [
    {
      "name": "n",
      "type": "STRING",
      "length": 140
    },
    {
      "name": "p",
      "type": "INT",
      "length": 11
    }
  ],
  "done": true,
  "totalRowCount": 2,
  "executionTime": 0.0019462108612060547
}