---
title: "Explore Yugabyte Cloud QL"
url: "https://docs.yugabyte.com/stable/quick-start/explore/ycql/"
---

# Explore Yugabyte Cloud QL

Explore Yugabyte Cloud QL (YCQL), a semi-relational distributed SQL API

- [YSQL](/stable/quick-start/explore/ysql/)
- [YCQL](/stable/quick-start/explore/ycql/)

After [creating a local cluster](/stable/quick-start/macos/ "creating a local cluster"), follow the instructions below to explore YugabyteDB's semi-relational [Yugabyte Cloud QL](/stable/api/ycql/ "Yugabyte Cloud QL") API.

[**ycqlsh**](/stable/api/ycqlsh/ "ycqlsh") is the command line shell for interacting with the YCQL API. You will use ycqlsh for this tutorial.

## Connect with ycqlsh

- [macOS](#macos)
- [Linux](#linux)
- [Docker](#docker)
- [Kubernetes](#kubernetes)

Run ycqlsh to connect to the service as follows:

```sh
$ ./bin/ycqlsh
```

```output
Connected to local cluster at 127.0.0.1:9042.
[ycqlsh 5.0.1 | Cassandra 3.9-SNAPSHOT | CQL spec 3.4.2 | Native protocol v4]
Use HELP for help.
ycqlsh>
```

Run a YCQL command to verify it is working.

```cql
ycqlsh> describe keyspaces;
```

```output
system_schema  system_auth  system
```

Run ycqlsh to connect to the service as follows:

```sh
$ ./bin/ycqlsh
```

```output
Connected to local cluster at 127.0.0.1:9042.
[ycqlsh 5.0.1 | Cassandra 3.9-SNAPSHOT | CQL spec 3.4.2 | Native protocol v4]
Use HELP for help.
ycqlsh>
```

Run a YCQL command to verify it is working.

```cql
ycqlsh> describe keyspaces;
```

```output
system_schema  system_auth  system
```

Run ycqlsh to connect to the service as follows:

```sh
$ docker exec -it yugabyte bash -c '/home/yugabyte/bin/ycqlsh $(hostname)'
```

```output
Connected to local cluster at 127.0.0.1:9042.
[ycqlsh 5.0.1 | Cassandra 3.9-SNAPSHOT | CQL spec 3.4.2 | Native protocol v4]
Use HELP for help.
ycqlsh>
```

Run a YCQL command to verify it is working.

```cql
ycqlsh> describe keyspaces;
```

```output
system_schema  system_auth  system

ycqlsh>
```

To connect to the service, open the YCQL shell (ycqlsh) by running the following command:

```sh
$ kubectl exec -it yb-tserver-0 -- ycqlsh yb-tserver-0
```

```output
Connected to local cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.9-SNAPSHOT | CQL spec 3.4.2 | Native protocol v4]
Use HELP for help.
ycqlsh>
```

Run a cql command to verify it is working.

```cql
ycqlsh> describe keyspaces;
```

```output
system_schema  system_auth  system

ycqlsh> 
```

## Create a table

Create a keyspace called 'myapp'.

```sql
ycqlsh> CREATE KEYSPACE myapp;
```

Create a table named `stock_market'`, which can store stock prices at various timestamps for different stock ticker symbols.

```sql
ycqlsh> CREATE TABLE myapp.stock_market (
  stock_symbol text,
  ts text,
  current_price float,
  PRIMARY KEY (stock_symbol, ts)
);
```

## Insert data

Let us insert some data for a few stock symbols into our newly created 'stock\_market' table. You can copy-paste these values directly into your ycqlsh shell.

```sql
ycqlsh> INSERT INTO myapp.stock_market (stock_symbol,ts,current_price) VALUES ('AAPL','2017-10-26 09:00:00',157.41);
INSERT INTO myapp.stock_market (stock_symbol,ts,current_price) VALUES ('AAPL','2017-10-26 10:00:00',157);
```

```sql
ycqlsh> INSERT INTO myapp.stock_market (stock_symbol,ts,current_price) VALUES ('FB','2017-10-26 09:00:00',170.63);
INSERT INTO myapp.stock_market (stock_symbol,ts,current_price) VALUES ('FB','2017-10-26 10:00:00',170.1);
```

```sql
ycqlsh> INSERT INTO myapp.stock_market (stock_symbol,ts,current_price) VALUES ('GOOG','2017-10-26 09:00:00',972.56);
INSERT INTO myapp.stock_market (stock_symbol,ts,current_price) VALUES ('GOOG','2017-10-26 10:00:00',971.91);
```

## Query the table

Query all the values you have inserted into the database for the stock symbol 'AAPL' as follows.

```sql
ycqlsh> SELECT * FROM myapp.stock_market WHERE stock_symbol = 'AAPL';
```

```output
 stock_symbol | ts                  | current_price
--------------+---------------------+---------------
         AAPL | 2017-10-26 09:00:00 |        157.41
         AAPL | 2017-10-26 10:00:00 |           157

(2 rows)
```

Query all the values for `FB` and `GOOG` as follows.

```sql
ycqlsh> SELECT * FROM myapp.stock_market WHERE stock_symbol in ('FB', 'GOOG');
```

```output
 stock_symbol | ts                  | current_price
--------------+---------------------+---------------
           FB | 2017-10-26 09:00:00 |        170.63
           FB | 2017-10-26 10:00:00 |     170.10001
         GOOG | 2017-10-26 09:00:00 |        972.56
         GOOG | 2017-10-26 10:00:00 |     971.90997

(4 rows)
```
