Learning Top SQL Commands with examples. - Pdf Slider

Learning Top SQL Commands with examples.

Learning Top  SQL Commands with examples.

To find a data line of work in 2023, you will have to learn SQL. Similarly, as with any language and particularly when you are a fledgling, it very well may be valuable to have a rundown of normal SQL orders and administrators in a single spot to allude to at whatever point you want it — we might want to be that spot for you!

The following is a complete rundown of SQL orders, coordinated by the high level of each (for example SELECT TOP is inside the SELECT class) in Top SQL Commands

In the event that you're on an excursion to learn SQL and you've been baffled by the absence of design or the dull educational plan made out of Google look, then, at that point, you might like Dataquest's intuitive SQL courses. Whether you're a novice attempting to prepare work or a carefully prepared engineer hoping to remain sharp, there's a SQL course for you.

SELECT

SELECT is probably the most commonly-used SQL statement. You’ll use it pretty much every time you query data with SQL. It allows you to define what data you want your query to return.

For example, in the code below, we’re selecting a column called name from a table called customers.

SELECT name

FROM customers;

SELECT *

SELECT used with an asterisk (*) will return all of the columns in the table we’re querying.

SELECT * FROM customers;

SELECT DISTINCT

SELECT DISTINCT only returns data that is distinct — in other words, if there are duplicate records, it will return only one copy of each.

The code below would return only rows with a unique name from the customer's table.

SELECT DISTINCT name

FROM customers;

SELECT INTO

SELECT INTO copies the specified data from one table into another.

SELECT * INTO customers

FROM customers_backup;

SELECT TOP

SELECT TOP only returns the top x number or percent from a table.

The code below would return the top 50 results from the customer's table:

SELECT TOP 50 * FROM customers;

The code below would return the top 50 percent of the customer's table:

SELECT TOP 50 PERCENT * FROM customers;

AS

AS renames a column or table with an alias that we can choose. For example, in the code below, we’re renaming the name column as first_name:

SELECT name AS first_name

FROM customers;

FROM

FROM specifies the table we’re pulling our data from:

SELECT name

FROM customers;

WHERE

WHERE filters your query to only return results that match a set condition. We can use this together with conditional operators like =, >, <, >=, <=, etc.

SELECT name

FROM customers

WHERE name = ‘Bob’;

AND

AND combines two or more conditions in a single query. All of the conditions must be met for the result to be returned.

SELECT name

FROM customers

WHERE name = ‘Bob’ AND age = 55;

OR

OR combines two or more conditions in a single query. Only one of the conditions must be met for a result to be returned.

SELECT name

FROM customers

WHERE name = ‘Bob’ OR age = 55;

BETWEEN

BETWEEN filters your query to return only results that fit a specified range.

SELECT name

FROM customers

WHERE age BETWEEN 45 AND 55;

LIKE

LIKE searches for a specified pattern in a column. In the example code below, any row with a name that included the character Bob would be returned.

SELECT name

FROM customers

WHERE name LIKE ‘%Bob%’;

Other operators for LIKE:

  • %x — will select all values that begin with x
  • %x% — will select all values that include x
  • x% — will select all values that end with x
  • x%y — will select all values that begin with x and end with y
  • _x% — will select all values have x as the second character
  • x_% — will select all values that begin with x and are at least two characters long. You can add additional _ characters to extend the length requirement, i.e. x___%

IN

IN allows us to specify multiple values we want to select when using the WHERE command.

SELECT name

FROM customers

WHERE name IN (‘Bob’, ‘Fred’, ‘Harry’);

IS NULL

IS NULL will return only rows with a NULL value.

SELECT name

FROM customers

WHERE name IS NULL;

IS NOT NULL

IS NOT NULL does the opposite — it will return only rows without a NULL value.

SELECT name

FROM customers

WHERE name IS NOT NULL;

CREATE

CREATE can be used to set up a database, table, index, or view.

CREATE DATABASE

CREATE DATABASE creates a new database, assuming the user running the command has the correct admin rights.

CREATE DATABASE dataquestDB;

CREATE TABLE

CREATE TABLE creates a new table inside a database. The terms int and varchar(255) in this example specify the datatypes of the columns we’re creating.

CREATE TABLE customers (

    customer_id int,

    name varchar(255),

    age int

);

CREATE INDEX

CREATE INDEX generates an index for a table. Indexes are used to retrieve data from a database faster.

CREATE INDEX idx_name

ON customers (name);

CREATE VIEW

CREATE VIEW creates a virtual table based on the result set of an SQL statement. A view is like a regular table (and can be queried like one), but it is not saved as a permanent table in the database.

CREATE VIEW [Bob Customers] AS

SELECT name, age

FROM customers

WHERE name = ‘Bob’;

DROP

DROP statements can be used to delete entire databases, tables, or indexes.

It goes without saying that the DROP command should only be used where absolutely necessary.

DROP DATABASE

DROP DATABASE deletes the entire database including all of its tables, indexes, etc as well as all the data within it.

Again, this is a command we want to be very, very careful about using!

DROP DATABASE dataquestDB;

DROP TABLE

DROP TABLE deletes a table as well as the data within it.

DROP TABLE customers;

DROP INDEX

DROP INDEX deletes an index within a database.

DROP INDEX idx_name;

UPDATE

The UPDATE statement is used to update data in a table. For example, the code below would update the age of any customer named Bob in the customer's table to 56.

UPDATE customers

SET age = 56

WHERE name = ‘Bob’;

DELETE

DELETE can remove all rows from a table (using ), or can be used as part of a WHERE clause to delete rows that meet a specific condition.

DELETE FROM customers

WHERE name = ‘Bob’;

ALTER TABLE

ALTER TABLE allows you to add or remove columns from a table. In the code snippets below, we’ll add and then remove a column for a surname. The text varchar(255) specifies the datatype of the column.

ALTER TABLE customers

ADD surname varchar(255);

ALTER TABLE customers

DROP COLUMN surname;

That's all. These all are the basic SQL Commands

Also, Read What is Figma Ui UX Design and Why Does it Matter?

YOU MAY ALSO LIKE

5 Strategies for a Successful Digital Marketing Agency in Malaysia in 2022

5 Strategies for a Successful Digital Marketing Agency in Malaysia in 2022

Customer needs are constantly evolving. Marketers and advertisers keep looking for new ways to understand their customers. However, there are several security concerns related to cookies and how enterprises resort to data collection.

03 March, 2022
2830 Views
How to Turn Off Google Lens on iPhone: A Step-by-Step Guide

How to Turn Off Google Lens on iPhone: A Step-by-Step Guide

We all understand how irritating it is to be incapable to find the right words to describe something we want to search for online. Google Lens is changing how we search by allowing us to search using images instead of words. This new tool is still in its early stages, but it has the chance to revolutionize the way we search the internet. However, it can be unpleasant sometimes, so this article will tell you about some great things about Google Lens and, if you don't like it, how to Turn off Google Lens on your iPhone.

11 November, 2022
2288 Views
Best Third-Party HP Printer Support Setup Services in the USA

Best Third-Party HP Printer Support Setup Services in the USA

In today's fast-paced digital world, printers remain an essential tool for both personal and professional use. Among the top printer brands, HP stands out for its reliability and performance. However, even the best printers can face issues from time to time. When you encounter problems with your HP printer, it's crucial to have reliable support at your fingertips. 123comsetup Provides third-party HP printer support services that have gained popularity for their convenience and expertise.

09 September, 2023
4629 Views

Similar Links

Similar PDFs

Crypto Wallet: Coinomi Wallet and Daedalus Wallet

Crypto Wallet: Coinomi Wallet and Daedalus Wallet

A cryptocurrency wallet is a piece of software that digitally stores the private keys necessary to sign bitcoin transactions on distributed ledgers. They're an important part of the cryptocurrency ecosystem since they're the only means to prove ownership of digital assets and conduct transactions that transfer or change them. They're also referred to as "crypto wallets," and they work similarly to the keys to a blockchain car. The car will not start without those keys. Without them, it would be impossible to verify ownership of a digital asset, which could be anything from a bitcoin to a token representing some type of asset.

09 September, 2021
1633 Views
Quantitative Aptitude Questions

Quantitative Aptitude Questions

Quantitative Aptitude Questions and Answers contains concepts and test papers on many topics such as problem on trains, time and work, simple interest, compound interests, partnership, problem on ages, average, numbers, calendar, boats and streams, clock, height, and distance, percentage, pipes and cisterns, profit and loss, speed, time and distance, etc.

05 May, 2021
1362 Views
Crypto Wallet: Coinomi and Coingate

Crypto Wallet: Coinomi and Coingate

Cryptocurrency wallets are specialized software programs that interact with different blockchain networks. Blockchains are digital ledgers that record a crypto coin's full history, including all of its transactions.

09 September, 2021
1508 Views