SQL Advanced | Wildcards

SQL Webp

SQL Wildcard Examples We have the following “Persons” table: Using the % Wildcard Now we want to select the persons living in a city that starts with “sa” from the “Persons” table. We use the following SELECT statement: The result-set will look like this: Next, we want to select the persons living in a city … Read more

SQL | The BETWEEN Operator

SQL Webp

BETWEEN Operator Example The “Persons” table: Now we want to select the persons with a last name alphabetically between “Hansen” and “Pettersen” from the table above. We use the following SELECT statement: The result-set will look like this: P_Id LastName FirstName Address City1 Hansen Ola Timoteivn 10 Sandnes The BETWEEN operator is treated differently in … Read more

SQL | The IN Operator

SQL Webp

The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax: IN Operator Example The “Persons” table: Now we want to select the persons with a last name equal to “Hansen” or “Pettersen” from the table above. We use the following SELECT statement: The result-set will look like this:

SQL | The INSERT INTO AND UPDATE Statement

The second form specifies both the column names and the values to be inserted: SQL INSERT INTO Example We have the following “Persons” table: Now we want to insert a new row in the “Persons” table.We use the following SQL statement: The “Persons” table will now look like this: Insert Data Only in Specified Columns … Read more

SQL | Alias Operator

SQL Webp

SQL Alias Syntax for Columns: Also read Alias Example Assume we have a table called “Persons” and another table called “Product_Orders”. We will give the table aliases of “p” and “po” respectively. Now we want to list all the orders that “Ola Hansen” is responsible for. We use the following SELECT statement: The same SELECT … Read more

SQL | The LIKE Operator

SQL Webp

SELECT column_name(s) FROM table_name WHERE column_name LIKE pattern LIKE Operator Example The “Persons” table: Now we want to select the persons living in a city that starts with “s” from the table above. We use the following SELECT statement: SELECT * FROM Persons WHERE City LIKE ‘s%’ The “%” sign can be used to define … Read more

SQL ADVANCE | The TOP Clause

SQL Webp

SELECT TOP number|percent column_name(s) FROM table_name SQL SELECT TOP Equivalent in MySQL and Oracle: MySQL Syntax: SELECT column_name(s) FROM table_name LIMIT number Example: SELECT * FROM Persons LIMIT 5 Oracle Syntax SELECT column_name(s) FROM table_name WHERE ROWNUM <= number Example SELECT * FROM Persons WHERE ROWNUM <=5 SQL TOP Example The “Persons” table: Now we … Read more

SQL | The DELETE Statement

SQL Webp

DELETE FROM table_name WHERE some_column=some_value Note: Notice the WHERE clause in the DELETE syntax. The WHERE clause specifies which record or records that should be deleted. If you omit the WHERE clause, all records will be deleted! SQL DELETE Example The “Persons” table: Now we want to delete the person “Tjessem, Jakob” in the “Persons” … Read more

SQL The ORDER BY Keyword

SELECT column_name(s) FROM table_name ORDER BY column_name(s) ASC|DESC ORDER BY Example The “Persons” table: Now we want to select all the persons from the table above, however, we want to sort the persons by their last name.We use the following SELECT statement: The result-set will look like this: ORDER BY DESC Example Now we want … Read more

SQL WHERE Clause

SQL Webp

The “Persons” table: Now we want to select only the persons living in the city “Sandnes” from the table above. We use the following SELECT statement using Where clause: The result-set will look like this: Quotes Around Text Fields in SQL WHERE CLAUSE SQL uses single quotes around text values (most database systems will also … Read more

SQL Introduction

SQL Webp

SQL is a standard language for accessing databases. How to use SQL to access and manipulate data in: MySQL, SQL Server, Access, Oracle, Sybase, DB2, and other database systems. SQL Syntax: SELECT Company, Country FROM Customers WHERE Country <> ‘USA’ SQL Result: SQL is a “standard language for accessing and manipulating databases”. What Can SQL … Read more

Pyspark Questions and Answers

Q1: Write pyspark code to create dataframe and print with ‘color’ and ‘weight’ as separate columns. inventoryData = [ (‘Laptop’, 20, {‘color’: ‘silver’, ‘weight’: 2.5}), (‘Phone’, 50, {‘color’: ‘black’, ‘weight’: 0.5}), (‘Tablet’, 30, {‘color’: ‘white’, ‘weight’: 0.8}), (‘Chair’, 10, {‘color’: ‘brown’, ‘weight’: 3.0}), (‘Printer’, 15, {‘color’: ‘gray’, ‘weight’: 7.5}), ] schema =[“Product”, “Quantity”, “Properties”] Product … Read more

Tips For Writing Efficient And Faster SQL Queries

SQL Banner

INTRODUCTION Query optimization is an important skill for SQL developers and database administrators (DBAs). In order to improve the performance of SQL queries, developers and DBAs need to understand the query optimizer and the techniques it uses to select an access path and prepare a query execution plan. Query tuning involves knowledge of techniques such … Read more