SQL查询从表中检索数据 [英] Sql query to retreive the data from a table

查看:85
本文介绍了SQL查询从表中检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨....我是sql的新手....有人可以指导我....我的要求是我在sql中有一个主表,它包含一个名为Head的字段,该字段是整数.主表包含Head ID(整数)...,主表中的Head ID也来自Head表,Head表包含Head_id(int),HeadName(varchar).....我的问题是如何写一个sql查询以从HEAD表中检索主表中的对应头名....以便可以在网格上显示头名,但不能在head_ids上显示头名..
谢谢

Hi....i am a newbee to sql....can someone guide me ....my requirement is i have a main table in sql and it contains a field by name Head which is an integer..the main tables contains the Head IDs(integer)...and also the head ids in the main table comes from the Head table which contains Head_id(int),HeadName(varchar).....my question is how to write a sql query to retreive the Corresponding headnames in the Main table from the HEAD table........so that headnames can be displayed on a grid but not head_ids..
thanks

推荐答案

使用select [coluumn1]. [column2] from [tablename]其中column1,column2等是您的字段名,[tablename]是您的表名.
Use select [coluumn1]. [column2] from [tablename] where column1, column2 etc are your field names and [tablename] is your tablename.


我不明白您的意思,但:
您有两个表,第一个称为"Main",另一个称为"Head"?

如何编写sql查询以从HEAD表中检索主表中的相应标题

为此,您需要使用加入",您可以阅读更多 http://www.w3schools.com/sql/sql_join.asp

或者您尝试以下简单方法:

I don''t understand fully what you mean but :
you''ve two tables, first called "Main" and other called "Head"?

how to write a sql query to retreive the Corresponding headnames in the Main table from the HEAD table

for this you need to use "join" you can read more http://www.w3schools.com/sql/sql_join.asp

or you try this simple:

select h.HeadName from Main m, Head h where h.id = m.Head_id;


这篇关于SQL查询从表中检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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