Home > Database > Mysql Tutorial > body text

mysql 合并两表的相同字段sql语句

WBOY
Release: 2016-06-07 17:52:57
Original
2008 people have browsed it

mysql 合并两表的相同字段方法很简单直接利用union联合查询即可实现。

SQL UNION 操作符
UNION 操作符用于合并两个或多个 SELECT 语句的结果集。

请注意,UNION 内部的 SELECT 语句必须拥有相同数量的列。列也必须拥有相似的数据类型。同时,每条 SELECT 语句中的列的顺序必须相同。

SQL UNION 语法

 代码如下 复制代码

SELECT column_name(s) FROM table_name1
UNION
SELECT column_name(s) FROM table_name2

 代码如下 复制代码

(SELECT ts.products_id,ts.sort from top_selling ts)

union(SELECT na.products_id,na.sort from new_arrival na)

order by rand()

limit 4

Related labels:
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