Home >Backend Development >PHP Tutorial > 同一个数据库中的两个表的查询,该如何解决

同一个数据库中的两个表的查询,该如何解决

WBOY
WBOYOriginal
2016-06-13 13:32:10817browse

同一个数据库中的两个表的查询
同一个数据库中的两个表怎么查询?例如名字为user和yong这个两个表 ,我要同时查询user这个表的username和yong这个表的name这两个字段要怎么查询?sql语句应该怎么写?具体一些谢谢哦

------解决方案--------------------
SELECT column_name(s) FROM table_name1
UNION ALL
SELECT column_name(s) FROM table_name2
------解决方案--------------------

SQL code

SELECT u.username,y.name FROM user AS u,yong AS y;
<br><font color="#e78608">------解决方案--------------------</font><br>
1、select a.*,b.* from a,b  <br>2、select a.*,b.* from a left join b on a.a1=b.b1<br>3、select a.* from a union all select b.* from b<br>比较有意义的是2;1,3看现场应用需要 <div class="clear">
                 
              
              
        
            </div>
Statement:
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