SQLite - 左连接 [英] SQLite - LEFT JOIN

查看:51
本文介绍了SQLite - 左连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要进行这样的查询:

I need to make a query like this:

SELECT table1.*, table2.column 
FROM table1 
LEFT JOIN table2 ON table1.column = table2.column

但它不起作用.如果我尝试相同的查询但替换第一部分 -->

But it's not working. If I try the same query but replacing the first part -- >

SELECT table1.column, table2.column 
FROM table1 
LEFT JOIN table2 ON table1.column = table2.column

它工作正常.我需要从 table1 中取出所有列.如何在不指定所有这些的情况下制作它?

it works fine. I need to bring all the columns from table1. How can I make it without specifing all of them?

推荐答案

如果table1table2中的列名相同,这里是不指定的解决方法table1 的所有列名:

If you have the same column name in table1 and table2, here is the solution for not specifying all the column name of table1 :

SELECT table1.*, table2.column as my_column_name_no_in_table1
FROM table1 
LEFT JOIN table2 ON table1.column = table2.column

如果table1table2的列名都不同,可以使用:

If the column names of table1 and table2 are all different, you can use :

SELECT table1.*, table2.*
FROM table1 
LEFT JOIN table2 ON table1.column = table2.column

但正如 peterm 的评论中所说,这在生产中并不是一个好的做法.现在,随心所欲!;)

But as said in the peterm's comment, it is not a good practice in production. Now, do as you want! ;)

这篇关于SQLite - 左连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆