Home > Database > SQL > body text

The keyword representing union in sql is

下次还敢
Release: 2024-05-01 23:42:43
Original
486 people have browsed it

The keyword representing union in SQL is UNION. The UNION operator combines rows from two or more tables into a single result set, retaining only unique rows. The syntax is: SELECT column1, column2, ... FROM table1 UNION SELECT column1, column2, ... FROM table2;. For example, to find all the names of students and teachers, we can use the following query: SELECT name FROM students UNION SELECT name FROM teachers;.

The keyword representing union in sql is

The keyword representing union in SQL: UNION

Union is an operator in SQL. Used to merge rows from two or more tables into a single result set, retaining only unique rows. The UNION keyword is used to perform this operation.

Syntax:

<code class="sql">SELECT column1, column2, ...
FROM table1
UNION
SELECT column1, column2, ...
FROM table2;</code>
Copy after login

Example:

Suppose there are two tables, students and teachers. We want to find the names of all students and teachers:

<code class="sql">SELECT name
FROM students
UNION
SELECT name
FROM teachers;</code>
Copy after login

The result will contain the names of students and teachers without duplicates.

The above is the detailed content of The keyword representing union in sql is. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!