Thursday, May 02, 2024

SQL Essential Training - LinkedIn

  • Datum - piece of information
  • Data is plural of datum. Data are piece of information - text, images or video.
  • Database - collection of data. Organized in many ways - tables. 
  • Tables - rows, and columns. Excel spreadsheet.
  • Col specifies attribute of that data.

An RDBMS (Relational Database Management System) is a program used to create, update, and manage relational databases. In a relational database, data is organized into tables, with each table containing rows (also known as records or tuples) and columns (attributes). Here are some key points about RDBMS:

  1. Table Structure:
    • An RDBMS structures information in tables, rows, and columns.
    • Each table represents a specific type of data (e.g., Customers, Orders).
    • Columns define the attributes (e.g., Customer ID, Order Date).
    • Rows contain actual data entries (e.g., individual customer records).
  2. Relationships:
    • RDBMS allows establishing relationships between tables using common attributes.
    • Instead of hierarchical structures, data is stored in related tables.
    • Primary keys uniquely identify rows, and foreign keys link related data.
  3. Example:
    • Consider a Customer table and an Order table:
      • Customer Table:
        • Customer ID (primary key)
        • Customer name
        • Billing address
        • Shipping address
      • Order Table:
        • Order ID (primary key)
        • Customer ID (foreign key)
        • Order date
        • Shipping date
        • Order status
    • By linking the Customer ID in both tables, we establish a relationship.
  4. Well-Known RDBMSs:
    • Some popular RDBMSs include MySQL, PostgreSQL, MariaDB, Microsoft SQL Server, and Oracle Database.

Here are some of the most popular Relational Database Management Systems (RDBMS):

  1. Oracle: As of September 2023, Oracle is the most popular RDBMS in the world, with a ranking score of 1240.88. It also holds the top position overall among all DBMS11.

  2. MySQL: MySQL is widely used and known for its open-source nature. It’s a popular choice for web applications and small to medium-sized databases.

  3. Microsoft SQL Server: Developed by Microsoft, SQL Server is commonly used in enterprise environments. It offers robust features, scalability, and integration with other Microsoft products.

  4. PostgreSQL: PostgreSQL is an open-source RDBMS known for its extensibility, ACID compliance, and support for advanced data types. It’s popular among developers and data professionals.

  5. IBM DB2: IBM DB2 is an enterprise-grade RDBMS with features like high availability, security, and scalability. It’s commonly used in large organizations.

  6. Microsoft Access: While not as powerful as the others, Microsoft Access is widely used for small-scale databases and desktop applications.

  7. SQLite: SQLite is a lightweight, embedded RDBMS often used in mobile apps and small projects.



WSDA Music


Company management wants to know what can we learn from the data? is there any useful info about sales, cust demographics, any ways company can improve / expand sales.

SQLite

SQLite is not a lighter version of SQL itself; rather, it is a lightweight relational database management system (RDBMS) that adheres to SQL specifications. Let’s explore why it’s named as such:


  1. Lightweight and Embedded:

    • SQLite focuses on providing a powerful SQL-compatible database without overheads or dependencies.
    • As the name implies, it’s a lightweight solution that can run on almost anything that supports C and persistent file storage.
    • Unlike traditional database systems that require a separate server process, SQLite is serverless and integrates directly into the application it serves.
  2. Key Features:

    • Embeddable: SQLite is embedded within the application, eliminating the need for a separate database server.
    • SQL Compatibility: Despite its lightweight nature, SQLite supports a vast majority of SQL standard features, making it robust enough for various applications.
    • File-Based: It operates directly on files, making it easy to manage and distribute.
  3. Use Cases:

    • Mobile Devices: SQLite is commonly used in mobile devices (such as Android and iOS) due to its small footprint and efficient storage.
    • Embedded Systems: It’s also popular in embedded systems, IoT devices, and desktop applications.
    • Testing and Prototyping: Developers often use SQLite for testing, prototyping, and small-scale projects.



Functions of each tab in DB Browser for SQLite:

  1. Database Structure:

    • In this tab, you can:
      • Create new database tables.
      • List existing database tables.
      • Delete database tables.
      • Define the structure of your database by specifying table names, columns, and their data types.
  2. Browse Data:

    • Here, you can:
      • View the actual data stored in your tables.
      • Browse through rows and columns.
      • Add new rows or modify existing data.
      • Essentially, it allows you to interact with the data in your database.
  3. Edit Pragmas:

    • The Edit Pragmas tab deals with system-wide parameters (pragmas) related to SQLite.
    • Pragmas are special commands that control various aspects of SQLite behavior.
    • You won’t typically need to change these settings unless you have specific requirements.
  4. Execute SQL:

    • This tab allows you to:
      • Write and execute SQL queries directly.
      • Query your database for specific information.
      • Inspect query results.
      • Perform operations like SELECT, INSERT, UPDATE, and DELETE.

Aliases



Operator Types



  • Select * from invoice where total in (1.98, 3.96)
  • Select * from Invoice where BillingCity in('Brussels', 'Orlando', 'Paris')
  • Select * from Invoice where BillingCity Like ('b%')
  • select * from invoice where total>1.98 AND (BillingCity like 'p%' OR BillingCity like 'd%')
  • Case statement
SELECT *,
CASE
When total < 2 THEN 'Baseline Purchase'
When total BETWEEN 2 and 6.99 Then 'Low Purchase'
When total between 7 and 15 then 'Target purchase'
Else 'Top performer'
END AS PurchaseType
From Invoice;

 


Filtering only the top performers by including the where clause....


JOINS

Getting data from 2 or more tables in a single SQL statement

Full list of customers (firstname and lastname) against all the invoices generated against that customer.

Entity-Relationship diagram for Invoice and Customer relationship.  


SYNTAX

Select * from Invoice
INNER JOIN
Customer
ON
Invoice.CustomerID = Customer.CustomerID
order by customer.CustomerId

// Above --- INNER JOIN or simply JOIN. 

Aliasing

Select c.CustomerId, c.LastName, c.FirstName, i.InvoiceId, i.InvoiceDate from Invoice as i
INNER JOIN
Customer as c
ON
i.CustomerID = c.CustomerID
order by c.CustomerId


Discrepancies between tables are handled with different join types


  • Customer with customerid 6 cannot be found in the customer table.
  • Customers with customerid 1 and 5  do not have entries in the invoice table. 
Inner Join

  • Inner join returns only matchting records.
  • Any umatched data from either tables is ignored.

Inner join will ignore customer 6 and customer 1 and 5. 






No comments:

Post a Comment

Full capabilities of ChatGPT 4 O (O for Omni) - From Openai.com

Omni, O, has multimodal capabitlies, which means it can take text, voice or video as an input and serve audio/text/image output (there's...