0% found this document useful (0 votes)
52 views4 pages

Queries in LibreOffice Base

The document provides a comprehensive guide on creating and executing queries in LibreOffice Base, including both graphical and SQL methods. It outlines the basic structure of SQL queries, common commands, and their purposes with examples. Additionally, it explains how to filter, sort, and manipulate data within a database.

Uploaded by

Charan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views4 pages

Queries in LibreOffice Base

The document provides a comprehensive guide on creating and executing queries in LibreOffice Base, including both graphical and SQL methods. It outlines the basic structure of SQL queries, common commands, and their purposes with examples. Additionally, it explains how to filter, sort, and manipulate data within a database.

Uploaded by

Charan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Queries in LibreOffice Base

# 1. What is a Query?
A query is used to retrieve, filter, sort, and manipulate data in a database. Q
Searching for specific records
Filtering data based on conditions
Sorting data in a particular order
Performing calculations

---

# 2. Ways to Create Queries in LibreOffice Base


LibreOffice Base allows us to create queries in two ways:

## A) Query Design View (Graphical method)


1. Open LibreOffice Base.
2. Click Queries - Create Query in Design View.
3. Select the table(s) from which you want data.
4. Choose the fields (columns) you need.
5. Set Sorting Order (Ascending/Descending).
6. Apply Filters (Conditions) if needed.
7. Click Run Query (F5) to see results.

## B) SQL Query (Manual Coding)


SQL (Structured Query Language) allows us to write queries manually.

---

# 3. Writing SQL Queries in LibreOffice Base


## A) Basic SQL Query Structure
SELECT column1, column2 FROM TableName WHERE condition;

- SELECT - Specifies which columns to retrieve


- FROM - Specifies the table name
- WHERE - Adds conditions (optional)
---

# 4. Common SQL Commands in LibreOffice Base

## A) Selecting All Data from a Table


SELECT * FROM Students;

This retrieves all columns from the Students table.

## B) Selecting Specific Columns


SELECT FirstName, LastName FROM Students;

This retrieves only the FirstName and LastName of students.

## C) Filtering Data Using WHERE Condition


SELECT * FROM Students WHERE Score > 80;

This retrieves students who scored more than 80.

## D) Sorting Data Using ORDER BY


SELECT FirstName, Score FROM Students ORDER BY Score DESC;

This retrieves students' names and scores, sorted in descending order.

## E) Using Multiple Conditions (AND / OR)


SELECT * FROM Students WHERE Score > 80 AND Class = '10A';

SELECT * FROM Students WHERE Score > 80 OR Age < 15;

## F) Using BETWEEN for Range Selection


SELECT * FROM Students WHERE Score BETWEEN 70 AND 90;

## G) Using IN for Multiple Values


SELECT * FROM Students WHERE Class IN ('10A', '10B', '10C');

## H) Using LIKE for Pattern Matching


SELECT * FROM Students WHERE FirstName LIKE 'A%';
SELECT * FROM Students WHERE FirstName LIKE '%a';

## I) Counting Number of Records (COUNT)


SELECT COUNT(*) FROM Students WHERE Score > 80;

## J) Finding the Highest (MAX) and Lowest (MIN) Values


SELECT MAX(Score) FROM Students;
SELECT MIN(Score) FROM Students;

## K) Finding the Average (AVG) and Total (SUM)


SELECT AVG(Score) FROM Students;
SELECT SUM(Score) FROM Students;

## L) Grouping Data Using GROUP BY


SELECT Class, AVG(Score) FROM Students GROUP BY Class;

## M) Updating Records (UPDATE)


UPDATE Students SET Score = 95 WHERE FirstName = 'John';

## N) Deleting Records (DELETE)


DELETE FROM Students WHERE Score < 40;

---

# 5. Running SQL Queries in LibreOffice Base


1. Open LibreOffice Base.
2. Click Queries - Create Query in SQL View.
3. Type the SQL query.
4. Click Run Query (F5) to see results.

---

# 6. Summary Table of SQL Commands

| SQL Command | Purpose | Example |


|------------|---------|---------|
| SELECT | Choose columns | SELECT Name FROM Students; |
| FROM | Choose table | FROM Students |
| WHERE | Add conditions | WHERE Age > 15; |
| ORDER BY | Sort results | ORDER BY Score DESC; |
| AND / OR | Multiple conditions | WHERE Score > 80 AND Age < 16; |
| BETWEEN | Select a range | WHERE Age BETWEEN 10 AND 15; |
| IN | Select multiple values | WHERE Class IN ('10A', '10B'); |
| LIKE | Pattern matching | WHERE Name LIKE 'A%'; |
| COUNT | Count rows | SELECT COUNT(*) FROM Students; |
| MAX / MIN | Find highest/lowest value | SELECT MAX(Score) FROM Stude
| AVG | Find average | SELECT AVG(Score) FROM Students; |
| SUM | Find total sum | SELECT SUM(Score) FROM Students; |
| GROUP BY | Group data | GROUP BY Class; |
| UPDATE | Modify data | UPDATE Students SET Score=90 WHERE Name='
| DELETE | Remove data | DELETE FROM Students WHERE Score < 40; |

---

This is a detailed guide on writing queries in LibreOffice Base.

You might also like