A shared folder with AI prompts and code snippets
From workspace: Cockroach Labs
Team: Main
Total snippets: 25
25 snippets
Use the SQL order by command to sort the result-set in ascending or descending order.
SELECT * FROM table_name ORDER BY column DESC;
The Left Join command in SQL returns all records from the left table and the matching records from the right table. The result is no records from the right side if there is not a match.
SELECT column_name(s) FROM table1 LEFT JOIN table2 ON table1.column_name = table2.column_name;
The Having command in SQL specifies conditions that filter which group results appear in the results.
SELECT column_name(s) FROM table_name WHERE condition GROUP BY column_name(s) HAVING condition ORDER BY column_name(s);
The Inner Join Command in SQL selects records that have matching values in both tables.
SELECT column_name(s) FROM table1 INNER JOIN table2 ON table1.column_name = table2.column_name;
The Group By command in SQL groups rows that have the same values into summary rows.
SELECT column_name(s) FROM table_name WHERE condition GROUP BY column_name(s) ORDER BY column_name(s);
The IN command in SQL allows you to specify multiple values in a WHERE clause.
SELECT column_name(s) FROM table_name WHERE column_name IN (SELECT STATEMENT);
The Union command in SQL is used to combine the result-set of two or more SELECT statements.
SELECT column_name(s) FROM table1 UNION SELECT column_name(s) FROM table2;
The OR command in SQL displays a record if any of the conditions separated by OR is TRUE.
SELECT column1, column2, ... FROM table_name WHERE condition1 OR condition2 OR condition3 ...;
This SQL code snippet inserts new records into a table.
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
The Update command in SQL is used to modify the existing records in a table.
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
The right join command in SQL returns all records from the right table and the matching records from the left table. The result is no records from the left side if there is not a match.
SELECT column_name(s) FROM table1 RIGHT JOIN table2 ON table1.column_name = table2.column_name;
The Full Join SQL command returns all records when there is a match in left or right table records.
SELECT column_name(s) FROM table1 FULL OUTER JOIN table2 ON table1.column_name = table2.column_name WHERE condition;
The Sum command in SQL returns the total sum of a numeric column.
SELECT SUM(column_name) FROM table_name WHERE condition;
The Count command in SQL returns the number of rows that matches a specified criterion.
SELECT COUNT(column_name) FROM table_name WHERE condition;
Use this SQL snippet to create a new table.
CREATE TABLE table_name ( column_name1 data_type(size), column_name2 data_type(size), column_name3 data_type(size), .... );
The Self Join SQL command is a regular join but the table is joined with itself.
SELECT column_name(s) FROM table1 T1, table1 T2 WHERE condition;
The Exists Command in SQL tests for the existence of any record in a subquery.
SELECT column_name(s) FROM table_name WHERE EXISTS (SELECT column_name FROM table_name WHERE condition);
Use the select SQL command to select data from a table.
SELECT * FROM table;
The Avg command in SQL returns the average value of a numeric column.
SELECT AVG(column_name) FROM table_name WHERE condition;
This sample SQL code displays a record if all the conditions separated by AND are true.
SELECT DISTINCT column1, column2, ... FROM table_name;
The select distinct command in SQL is used to return only distinct values.
SELECT DISTINCT column1, column2, ... FROM table_name;
The Between command in SQL selects values within a given range.
SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2;
The Like command in SQL is used to search for a specified pattern in a column.
SELECT column1, column2, ... FROM table_name WHERE column LIKE pattern;
The Delete command in SQL is used to delete existing records in a table.
DELETE FROM table_name WHERE condition;
This NOT SQL sample code snippet displays a record if the condition(s) is NOT TRUE.
SELECT column1, column2, ... FROM table_name WHERE NOT condition;