X
X
X
X

Basic SQL Commands for Beginners

HomepageArticlesBasic SQL Commands for Beginners

SQL (Structured Query Language) is the preferred tool for querying and organizing databases. If you are new to SQL commands or want some commands of this powerful tool at hand, our SQL commands page below is exactly what you need.

Basic SQL Commands

 

command function
Query Commands
SELECT It is the basic query used to pull data. It means Seçek. Determines the target you will question
SELECT * Using SELECT * allows you to target all columns.
SELECT column It is the command to select all milk.
SELECT table.column You target a specific table in a particular column.
FROM It is the command that determines where the data will be.
AS The temporary name of a new name for a table name or column.
WHERE Filters the results with one condition.
AND More than one query criteria is determined with the WHERE command. It must be in both conditions in the determined criteria. For example, if you want to question men with black hair in the database, you will question the results of both men with black hair. The data that you have in two crises results.
OR More than one query criteria is determined with the WHERE command. It is sufficient to have one of the two runners in the specified criteria. As an example, if you want to question men with black hair in the database, the results of the inquiry that are either black hair or men are listed. It is enough to have one of these two criteria.
ORDER BY It is the command that provides the results to be sorted.
ORDER BY column ASC Sorts the results as "ascending" in a column
ORDER BY column DESC Sorts the results as "descending" in a column
LIMIT Limits the number of results
OFFSET OFFSET skips the first line of the recording. It is usually used with LIMIT.
subqueries Used to retrieve data from another query.
Aggregation Functions
COUNT Indicates the number of records obtained in the query.
MAX Determines the highest value in a numerical column
MIN  Determines the lowest value in a numerical column
SUM Adds numerical values ​​in a column.
AVG Returns the average value in a numeric column
HAVING Used with aggregate functions instead of the WHERE clause.
GROUP BY Offers results by grouping
operators
LIKE Used with% to search for a search value in a column. It is used to find the expression in it. For example, when you type Last%, it lists the last values ​​in the last.
ILIKE Used to determine the search value without being bound to upper / lower case
BETWEEN Used to search for a value between two values. This usually works with Date or number.
> Searches for larger values ​​than condition
> = Searches for values ​​greater than or equal to a condition
< Searches for values ​​lower than the condition
<= Searches for values ​​less than or equal to a condition
= Searches for values ​​that exactly match a condition
<> Search for values ​​that are not equal to a condition.
UNION Combine two unique queries (with the same columns) into one result.
UNION ALL Combine two queries (with the same columns) into one result. Copies are allowed.
OF WHERE shortcut. Specifies multiple OR conditions.
NOT IN WHERE shortcut. Specifies multiple OR conditions or not.
IS NULL Null values
IS NOT NULL Checks for null values
INTERSECT Results matching two queries
MINUS Results in a query that are not in another query
coupling
FRONT Used to determine columns to compare and match results.
USING The shortcut is used for ON when the column name is the same in both tables.
LEFT OUTER JOIN All results in the left table, only matching results in the right table.
LEFT OUTER JOIN (WITH NULL) (With Null) All results in the left table, but not in the right table.
INNER JOIN All matching results in both left and right tables.
FULL OUTER JOIN All results of the left and right tables.
FULL OUTER JOIN (WITH NULL) (With Null) All results from both left and right tables, excluding results in both tables.
RIGHT OUTER JOIN All results in the right table, with only matching results from the left table.
RIGHT OUTER JOIN (WITH NULL) (With Null) All results in the table on the right, not in the table on the left.
Creating and Editing Tables
CREATE TABLE Create a new table.
NULL Allow nulls for this field.
NOT NULL Do not allow null values ​​for this field.
DEFAULT Value to fill the field if not provided.
AS Creates a new table based on the structure of an existing table. The new table will contain the data in the old table. It will copy a table.
ALTER TABLE (ADD COLUMN) Adds a new column to an existing table.
ALTER TABLE (DROP COLUMN) Removes a column from an existing table.
ALTER TABLE (ALTER COLUMN) Changes the data type of an existing column.
ALTER TABLE (RENAME COLUMN) Renames an existing column.
ALTER TABLE (RENAME TABLE) Renames an existing table.
ALTER TABLE (MODIFY NULL) Allows null values ​​for a column
ALTER TABLE (MODIFY NOT NULL) Prevents null values ​​for a column
DROP TABLE Deletes a table and all its data
TRUNCATE TABLE Deletes all the data in a table, but not the table itself.
Limitations
PRIMARY KEY A value that uniquely identifies a record in the table. NOT NULL and UNIQUE combination.
FOREIGN KEY A unique value references another table. It is usually the primary key in the table.
UNIQUE Require unique values ​​for this column per table.
CHECK It ensures that the values ​​are suitable for a certain condition.
INDEX (CREATE) It optimizes tables and greatly speeds up queries by adding indexes to a column.
INDEX (CREATE UNIQUE) Creates an index that does not allow duplicate values.
INDEX (DROP) Removes a directory.
Creating and Editing Data
INSERT (SINGLE VALUE) Adds a new record to a table.
INSERT (MULTIPLE VALUES) Adds several new records to a table.
INSERT (SELECT) Add a record to a table, but takes values ​​from an existing table
UPDATE (ALL) Replaces all existing records in the table
UPDATE (WHERE) Replaces existing records that match the condition in a table.
DELETE (ALL) Deletes all the records in a table.
DELETE (WHERE) Deletes records from a specified table.
Creating and Editing Triggers
CREATE TRIGGER Creates a trigger.
CREATE TRIGGER (OR MODIFY) Create a trigger or update an existing trigger if there is a trigger with the same name.
WHEN (BEFORE) Run the trigger before the event occurs.
WHEN (AFTER) Run the trigger after the event occurs.
EVENT (INSERT) Operate the trigger before or after a insert occurs.
EVENT (UPDATE) Run the trigger before or after the update takes place.
EVENT (DELETE) Run the trigger before or after deletion.
FRONT Determine which table to target with this trigger.
TRIGGER_TYPE (FOR EACH ROW) Execute the trigger for each changing line.
TRIGGER_TYPE (FOR EACH STATEMENT) Regardless of how many lines have been changed, run the trigger once per SQL statement.
EXECUTE Keyword indicating the end of the main trigger definition.
DROP TRIGGER Delete a trigger.
Creating and Editing Views
CREATE VIEW Create a new look.
AS Define where to get the data for a view.
WITH CASCADED CHECK OPTION Make sure that the data changed through the view conforms to the rules defined by the rule. Apply this to other views.
WITH LOCAL CHECK OPTION Make sure that the data changed through the view conforms to the rules defined by the rule. Disregard this for other views.
CREATE RECURSIVE VIEW Create a recursive view.
CREATE TEMPORARY VIEW Creates an existing view for the current session only.
DROP VIEW Delete a view.
Common Table Expressions (CTEs) 
WITH Creates a new common table expression.
AS Specifies the data to be used in CTE
(COMMA) Chains multiple CTEs.
Makalemizle iİlgili Görüşlerini Belirtebilirsin


Bir Sorunuz mu Var?

Sorularınızı cevaplamayı bekleyen muhteşem bir ekibimiz var.
Bize Ulaşın.