PHP-Einfach.de
  • PHP Tutorial
  • MySQL Tutorial
  • Für Fortgeschrittene
  • Webhosting
  • Forum

Übersicht SQL-Befehle

10. Februar 2020
  1. Home
  2. »
  3. MySQL Tutorial
  4. »
  5. Übersicht SQL-Befehle

Nachfolgend findet ihr einen Überblick über die wichtigsten SQL-Befehle. In unserem MySQL-Tutorial sind diese auch jeweils ausführlicher beschrieben und mit Beispielen versehen. Diese Seite dient eher als Nachschlagewerk.

Inhaltsverzeichnis

  • 1 Abfragen von Daten
  • 2 Daten filtern
  • 3 Daten sortieren
  • 4 Datensätze zählen
  • 5 Join von Tabellen
  • 6 Daten einfügen
  • 7 Daten löschen
  • 8 Daten aktualisieren
  • 9 Tabelle leeren

Abfragen von Daten

Abfragen von gewissen Datenbank-Spalten:

1
SELECT spalte1, spalte2, spalte2 FROM tabelle

Abfragen aller Spalten:

1
SELECT * FROM tabelle

Abfrage der eindeutigen Datensätze:

1
SELECT DISTINCT spalte1, spalte2 FROM tabelle

Weitere Infos: Simple Datenabfrage per SELECT

Daten filtern

Simple WHERE-Klausel:

1
SELECT * FROM tabelle WHERE spalte = 'Wert'

Logische Operatoren:

1
SELECT * FROM tabelle WHERE (spalte1 = 'Wert1' AND spalte2 = 'Wert2') OR (spalte3 = 'Wert3')

Größer- und Kleiner-Vergleiche

1
SELECT * FROM tabelle WHERE spalte1 < 10 AND spalte2 >= 5

Weitere Informationen: Komplexere Datenabfrage per SELECT

Daten sortieren

Daten aufsteigend sortieren:

1
SELECT * FROM tabelle ORDER BY spalte1, spalte2, spalte3

Daten absteigend sortieren:

1
SELECT * FROM tabelle ORDER BY spalte1 DESC

Weitere Informationen: Simple Datenabfrage per SELECT

Datensätze zählen

1
SELECT COUNT(*) FROM tabelle

Eindeutige Werte zählen:

1
SELECT COUNT(DISTINCT spalte) FROM tabelle

Werte gruppieren und zählen:

1
SELECT spalte1, COUNT(*) FROM tabelle GROUP BY spalte1

Weitere Informationen: Gefundene Einträge zählen mittels COUNT

Join von Tabellen

1
2
SELECT tabelle1.spalte1, tabelle1.spalte2, tabelle2.spalte1 FROM tabelle1
LEFT JOIN tabelle2 ON tabelle2.tabelle1_id = tabelle1.id

Weitere Infos: MySQL LEFT Join

Daten einfügen

1
INSERT INTO tabelle (spalte1, spalte2, spalte3) VALUES ('Wert1', 'Wert2', 'Wert3')

Oder alternativ:

1
INSERT INTO tabelle SET spalte1='Wert1', spalte2='Wert2', spalte3='Wert3'

Weitere Informationen: Daten einfügen per INSERT

Daten löschen

1
DELETE FROM tabelle WHERE id = 1

Weitere Informationen: Daten löschen mittels DELETE

Daten aktualisieren

1
UPDATE tabelle SET spalte1='Wert1', spalte2='Wert2' WHERE id=1

Weitere Informationen: Daten aktualisieren per UPDATE

Tabelle leeren

Um sämtliche Inhalte einer Tabelle zu leeren:

1
TRUNCATE tabellen_name

Autor: Nils Reimers
Zurück: MySQL Fremdschlüssel
Weiter: Crashkurs MySQL

MySQL Tutorial

  • MySQL installieren und starten
  • phpMyAdmin
  • Verbindung aufbauen
  • Simple Datenabfrage
  • Komplexere Datenabfrage
  • Prepared Statements
  • Daten einfügen
  • Daten aktualisieren
  • Daten löschen
  • Gefundene Einträge zählen
  • DATE-Datenbankspalten
  • Datum- und Zeitfunktionen
  • MySQL Fehlermeldungen
  • Datenbankverbindung schließen
  • JOIN
  • Indizes
  • Normalformen
  • Fremdschlüssel
  • Übersicht SQL-Befehle
  • Crashkurs MySQL
  • Crashkurs MySQLi
  • Crashkurs PDO
Mit freundlicher Unterstützung von:
  • Punkt191 Werbeagentur
  • DGUV V3
  • DGUV 3
  • CasinoAndy Finland
  • Casinopilot24.com
  • Neueonline-Casinos.com
  • CasinoHEX.at
  • Decasinos.de
  • Privatkredit247.com
  • Online Casino Spielautomaten
  • Casinofrog.com
  • parhaatuudetkasinot.com

Hoster – Geringste Ausfallzeit

  1. webgo Ø 0 Min.
  2. Linevast Ø 3 Min.
  3. netcup Ø 3 Min.
  4. dogado Ø 6 Min.
  5. Mittwald Ø 9 Min.
  6. All-Inkl.com Ø 10 Min.
  7. manitu Ø 10 Min.
  8. bplaced Ø 11 Min.
  9. checkdomain Ø 11 Min.
  10. Host Europe Ø 14 Min.
» Mehr erfahren

Impressum | Datenschutz | Auf PHP-Einfach.de werben

© PHP-Einfach.de 2003 - 2022

Um dich beim Lernen von PHP und MySQL zu unterstützen verwenden wir Cookies. OK Weitere Infos
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Notwendige
immer aktiv

Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.

Nicht notwendige

Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.