SQL Query Basics

SQL Query Basics

Below is an example of a very basic SQL query:

SELECT

u.id AS 'id',  
u.username AS 'username',
u.firstname AS 'first name',
u.lastname AS 'last name',
u.email AS 'email'

FROM prefix_user AS u 

WHERE u.id > 2


The SELECT statement is used to select data FROM a database table. We can assign an alias to the database table using the AS statement as shown above. This is useful as it prevents you having to rewrite the database table over and over again when creating columns using the SELECT syntax.

id, username, firstname, lastname and email are all columns from the database table with the associated column heading you give them.

For more information on the Pluto LMS database tables, click here.


The WHERE clause is used to filter your records that fulfil a specified condition.

The above query will produce the following sample table:


id
username
first name 
last name
email
3
joesoap
Joe
Soap
js@e.com
4
salwhite
Sal
White
sw@e.com
5
themb
Them
B
tb@e.com
6
jess
Jess
Sky
js@e.com



For more help on SQL syntax, please visit https://www.w3schools.com/sql/




    • Related Articles

    • SQL Templates

      Note that assistance with writing SQL queries is not within Pluto LMS support scope. Please contact a developer for assistance.  That being said, you can use the templates provided below to help you get started. Please review our other guides for ...
    • Adding Filters

      OVERVIEW When creating a custom report, you can add filters that function as a control which produces a subset of data.  ADDING A FILTER In the relevant custom report, in the "Filters" tab,  select the filter that you require from the "Add" drop-down ...
    • Creating a Custom Report

      OVERVIEW The Custom Reports module allows you to create custom reports to supplement the native Pluto LMS reports.  Note: This may require the assistance of a developer.  CREATE A CUSTOM REPORT Step 1: Click on "Site admin", followed by "Site ...
    • IP Blocker

      OVERVIEW Users with the "Site admin" role can set a list of allowed and/or blocker IP addresses in Site admin.   UNDERSTAND MORE ABOUT IP ADDRESSES You can click on the following links to learn more about IP Addresses: Understand the basics of IP ...
    • Database Structure

      Visualising the Pluto LMS Database: The below graphic will help you visualize how each database table connects to the other. Some important notes: This is a simplified graphic and in many instances you can have more than one connection across tables. ...