从两个表的SQL选择语句 [英] sql select statement from two table

查看:154
本文介绍了从两个表的SQL选择语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在sql server中有两个表.country表和detail表.
明细表的国家/地区ID大于10,表示明细表有10条记录
但我只想从详细信息表中选择一条记录,如何完成,请帮助我,这将是极大的帮助
谢谢

i have two table in sql server .country table and detail table.
detail table a country id more than 10.it means that detail table have 10 record
but i want to select only one record from detail table how it is done plz help me that will be greate help
thanks

推荐答案

从您的描述中很难很精确,但是请看一下SQL SELECT语句的WHERE子句: ^ ]

It''s difficult to be precise from your description, but have a look at the WHERE clause of the SQL SELECT statement: W3Schools[^]

SELECT * FROM myTable WHERE country='India'


您始终可以在两个表上进行LEFT JOIN并选择TOP行.
You can always just do a LEFT JOIN on the two tables and select the TOP row.


从问题描述中还不清楚,"details"表的10条记录是否为与同一个国家(条目)相关,或与所有国家(条目)相关.

如果详细信息用于不同的国家/地区,则需要使用INNER JOIN语句选择每个国家/地区及其详细信息,但是如果10个详细信息与同一国家/地区相关,则您有两个选择:

1.确定了详细信息,然后可以使用WHERE语句.
2.详细信息未确定,WHERE语句不适用.在这种情况下,您需要检查数据库设计或不必要的数据冗余.
It is not clear from the problem description if the 10 records of "details" table are related to the same country (entry), or related to all countries (entries).

If the details are for different countries, then you need to use INNER JOIN statement to select each country with its details, but if the 10 details are related to the same country then you have two options:

1. The details are identified, then you can use WHERE statement.
2. The details are not identified and WHERE statement is not applicable. In this case you need to check you database design or unnecessary data redundancy.


这篇关于从两个表的SQL选择语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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