Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Basics SQL - SELECT Information
Anne Quinkenstein
Anne Quinkenstein

Posted on • Edited on

     

Basics SQL - SELECT Information

Cheat-Sheet

Statements

SELECT

SELECTcolumn1,column2,...FROMtable_name;
Enter fullscreen modeExit fullscreen mode
SELECT*FROMtable_name;
Enter fullscreen modeExit fullscreen mode

Filter withWHERE

SELECT firstname, birthday FROM customers WHERE lastname='Mueller';
Enter fullscreen modeExit fullscreen mode
  • an equal value= or different value!=
  • a higher value> (or higher than or equal to>=), a lower value< (or lower than or equal to<=)
  • a value from several possible values withIN
  • a numerical value (or a date) from within a rangeBETWEEN xx AND yy
  • a chain starting with or ending with withLIKE and the% joker
  • a valueIS NULL orIS NOT NULL

Limit the result

SELECT <champs> FROM <table> LIMIT <nb_results>;
SELECT * FROM customer LIMIT 5 OFFSET 20;
Be careful: it is a common mistake to write LIMIT 25 OFFSET 20, assuming this will retrieve results 21 to 25, but it would actually return results 21 to 45!)

ORDER BY Sorting and filtering

SELECT firstname, lastname FROM customer ORDER BY lastname ASC, birthday DESC;
the youngest Memebers of Müller:

SELECT*FROMcustomerWHERElastname='Müller'ORDERBYbirthdayDESCLIMIT0,3;
Enter fullscreen modeExit fullscreen mode

AChallenge - try yourself

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Software Engineer (Java)
  • Location
    Berlin, Germany
  • Work
    Testautomation Engineer at Telecolumbus
  • Joined

More fromAnne Quinkenstein

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp