SQL for Everybody

Harness the power of AI to write SQL (Structured Query Language) effortlessly. Get the precise SQL queries and data you need, exactly when you need them.

Get started for free

Effortless use and learn SQL

SQL is the standard language for interacting with databases, enabling you to retrieve, add, update, and delete data. Whether you're using MySQL, PostgreSQL, MSSQL, or other relational databases, our AI-powered tool makes SQL accessible to everyone.
Below, you can see how easy it is to use AI to generate various SQL statements and clauses. The SQL examples are based on the video rental store database, Sakila for MySQL. (SQL queries for other databases are very similar.)
If you examine the Sakila database schema, you'll notice it consists of separate tables. Some of these tables are interconnected, such as customer and rental, using a foreign key. Rows in the rental table that belong to a specific customer are referenced using the customer_id field. This concept is fundamental to relational databases, allowing for effective organization and connection of diverse data.

SQL SELECT statement

The SELECT statement is used to select data from a database (as opposed the INSERT or DELETE statement).
Get customers
            
SELECT * FROM customer;

SQL WHERE clause

The WHERE clause is used to filter records. It can be used in SELECT, UPDATE, WHERE and other statements to filter records.
Get customers named Smith
            
SELECT customer_id, -- Retrieve specified columns instead of all using * first_name, last_name FROM customer WHERE last_name = 'Smith';

SQL ORDER BY clause

The ORDER BY clause is used to sort the result-set in ascending or descending order. It is used with the SELECT statement.
Get customers ordered by last name
            
SELECT customer_id, first_name, last_name FROM customer ORDER BY last_name ASC;

SQL FROM keyword

The FROM keyword is used to specify the table from which to retrieve records. It is used in conjunction with multiple SQL statements, e.g. SELECT or DELETE.
Get all customers
            
SELECT * FROM customer;

SQL GROUP BY clause

The GROUP BY statement groups rows that have the same values in one or more columns into a summary row, like "find the number of customers in each country".
The GROUP BY statement is often used with aggregate functions (COUNT, MAX, MIN, SUM, AVG) to group the result-set by one or more columns.
Count the number of customers in each country
            
SELECT COUNT(customer_id), country FROM customer GROUP BY country;
We assume the customer table has a country column.

SQL JOIN clause

The JOIN clause is used to combine rows from two or more tables, based on a related column between them.
Get each customer with their address
            
SELECT customer.customer_id, customer.first_name, customer.last_name, address.address, address.district FROM customer JOIN address ON customer.address_id = address.address_id;

SQL LIMIT clause

The LIMIT clause is used to constrain the number of rows returned by the SELECT statement.
The LIMIT clause is typically used with large datasets where you want to avoid returning a huge number of rows or for pagination.
Get the first 5 customers
            
SELECT customer_id, first_name, last_name FROM customer LIMIT 5;

SQL INSERT Statement

The INSERT INTO statement is used to insert new records (rows) into a table.
Insert a new customer named John Doe with email john.doe@example.com
            
INSERT INTO customer ( first_name, last_name, email, address_id, store_id, active, create_date ) VALUES ( 'JOHN', 'DOE', 'john.doe@example.com', 1, 1, 1, NOW () );

SQL DELETE Statement

The DELETE statement is used to delete existing records in a table.
Delete customer named "JANE" "DOE"
            
DELETE FROM customer WHERE first_name = 'JANE' AND last_name = 'DOE';
NOTE:The WHERE clause is crucial; omitting it will delete all records in the table. The above will delete all records with the first_name "JANE" and last_name "DOE".

SQL UPDATE statement

The UPDATE statement is used to modify the existing records in a table. It is usually combined with a WHERE clause to specify which record(s) to update.
Update email to mary.smith@sakilacustomer.org for customer with id 34
            
UPDATE customer SET email = 'mary.smith@sakilacustomer.org' WHERE customer_id = '31';
Note: Always use a WHERE clause when updating records, unless you want to update ALL records!

Advanced SQL queries

Here are some examples of advanced SQL queries generated by AI.
Get customers who didn't make a purchase in the last 12 months but a purchase in the 12 months before that
            
SELECT c.customer_id, c.first_name, c.last_name FROM customer AS c JOIN payment AS p ON c.customer_id = p.customer_id WHERE p.payment_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 24 MONTH) AND DATE_SUB(CURDATE(), INTERVAL 12 MONTH) AND c.customer_id NOT IN( SELECT p2.customer_id FROM payment AS p2 WHERE p2.payment_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 12 MONTH) AND CURDATE() ) GROUP BY c.customer_id, c.first_name, c.last_name;

Why use SQLAI.ai?

We've packed our platform with powerful features to make your SQL workflow smoother and more efficient. Here's a glimpse of what we offer:

Create, Improve, and Understand Your SQL

From generating queries from scratch to fine-tuning existing ones, we've got you covered.

Seamless Database Integration

Connect your database effortlessly and start working with your data in seconds.

Handy Tools for SQL Power Users

Boost your productivity with helpful features conveniently located right where you need them.

  • Run SQL (and NoSQL) queries directly on your connected database
  • A full-featured SQL editor (VS Code)
  • Easily compare improved SQL with "view diff"
  • And more tools to streamline your workflow!

Supported Databases

See all databases on the settings page or add it here.
MySQL icon
MySQL
Connect
PostgreSQL icon
PostgreSQL
Connect
SQL Server (MS) icon
SQL Server (MS)
Connect
Oracle PL/SQL icon
Oracle PL/SQL
Connect
BigQuery icon
BigQuery
MongoDB icon
MongoDB
Connect

Get started with SQL

Start boosting your productivity and skills by generating SQL and retrieve valuable data insights, without waiting for the data team.

FAQ