![](/img/trans.png)
[英]SQL query to copy from some columns of a table to one column in another table
[英]SQL Query that retrieves all columns from one table and one column from the another
假设我们有下表:
Products [ItemID,ItemName,ItemDesc]
ProductInSupermarket [ItemID,SupermarketID,ItemPrice]
并且我们想从ProductInSupermarket
Products
和ItemPrice
检索所有内容,有没有办法提及所有列呢? 我的意思是,我们可以做到:
Select Products.ItemID,Products.ItemName,Products.ItemDesc,ItemPrice
FROM Products,ProductInSupermarket
WHERE Products.ItemID=ProductInSupermarket.ItemID;
但是,当我们有一个包含许多列的表并且想要从该表以及其他一些表中检索全部内容时,这不太容易理解。 如何以更易读和有效的方式编写此查询?
我回显@DCoder的注释 ,但要补充一点,您还可以省略没有歧义的表限定符,并使用显式联接语法和USING
来更加简洁:
SELECT Products.*, ItemPrice
FROM Products JOIN ProductInSupermarket USING (ItemID)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.