Form of Basic SQL Query in DBMS
Form of Basic SQL Query in DBMS
FROM: Specifies the table from which you're retrieving the data.
GROUP BY: Groups rows that have the same values in specified columns.
JOIN: Combines rows from two or more tables based on related columns.
• 1. Retrieve all columns from a table:
• Syntax
•
2. Retrieve specific columns from a table:
• Syntax
• Syntax
• SELECT column1, column2 FROM tablename ORDER BY column1 ASC;
Regular expressions in the SELECT Command
• Regular expressions: is a sequence of characters that define a search pattern, mainly for use in pattern
matching with strings, or string matching.
• Examples:
Finds names that start with "a" and are at least 3 characters in length.
• LIKE: The LIKE operator is used in a 'WHERE' clause to search for a specified pattern in a column
• Wild cards:
• percent sign (%) Represents zero, one, or multiple characters
• Syntax
• SELECT column_name
• FROM table_name
• For example, to find all customers whose names start with "Ma":
• SELECT FirstName
• FROM Customers
• SELECT column_name
• FROM table_name
• WHERE column_name LIKE '%pattern’;
• FROM Products
• WHERE ProductName LIKE '%ing';
Find values that have a specific pattern anywhere:
• SELECT column_name
• FROM table_name
• Example, to find all books that have the word "life" anywhere in the title:
• SELECT BookTitle
• FROM Books
• 1. Find values of a specific length where you only know some characters:
Syntax
• SELECT column_name
• FROM table_name
• For instance, if you're looking for a five-letter word where you know the first letter is "h" and the
third letter is "l", you could use:
• SELECT Word
• FROM Words
• The UNION operator in DBMS is used to combine the result sets of two or m
• ore SELECT statements. However, it will only select distinct values.
• SELECT City FROM Customers
• UNION
• UNION ALL
• The INTERSECT operator in a DBMS is used to combine two SELECT statements and
return only the records that are common to both.
• SELECT order_id FROM Orders
• INTERSECT
• Syntax
• This would also return ids that exist in both table1 and table2.
Except in DBMS
• EXCEPT
• ON o.OrderID = d.OrderID