Code Monkey home page Code Monkey logo

jackbayly-orderby's Introduction

Background

SQL sublanguage: DQL (Data Query Language)

When we query a database for information, that information is not necessarily ordered. Physically, that information is serialized in some order, but it is not necessarily the order you might expect, and the order is subject to change. When querying for information we usually want to indicate the order for our results. This is done with the ORDER BY clause.

Example:

SELECT * FROM table_name ORDER BY column1 [, column2, column3, etc...] [ASC|DESC]

When ordering by multiple columns, the priority is from left to right.

We can order by columns in ascending or descending order. By default, ORDER BY is in ascending order. Ascending order places lesser values before greater values. Descending order is the opposite, greatest values first.

For example, one might add the ORDER BY clause after the WHERE clause of a query to order employees from highest to lowest salary:

SELECT * FROM employee_table WHERE current = true ORDER BY salary DESC

Additional reference material if needed: https://www.w3schools.com/sql/sql_orderby.asp


Lab

Problem 1

character table

id first_name last_name
1 'Leto' 'Atreides'
2 'Vladimir' 'Harkonnen'
3 'Jessica' 'Atreides'
4 'Paul' 'Atreides'
5 'Feyd-Rautha' 'Harkonnen'

Problem 1: Write a statement below to query the database for all characters. Make sure the results are in ascending order by last name, and first name as a tie-breaker.

jackbayly-orderby's People

Contributors

jackbayly avatar kevinchilds avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.