Discover sql query to compare two columns in same table, include the articles, news, trends, analysis and practical advice about sql query to compare two columns in same table on alibabacloud.com
. The link allows you to retrieve data from two or more tables at the same time and specify one or more columns in these tables as the join condition. In SQL Server, two types of connection syntax can be used, one is the ANSI link syntax, which is the connection condition in the FROM clause; the other is the SQL Server link syntax, this is the connection conditio
, which is generally used to guide some data CREATE TABLE student_table ( stuid varchar, CourseID varchar, grade int ) CREATE TABLE Student ( stuid varchar, CourseID varchar, grade int ) INSERT into student_table values (' 10001 ', ' 001 ', ' I ') INSERT into student_table values (' 10002 ', ' 001 ', ' 95 ')INSERT INTO studentSELECT * from student_table as S1where S1.stuid n
table [table name] Add field name the datetime default function increases the date Type field, where the function can be now (), date (), and so on, representing the default value (which is most commonly used, and other properties, which can be referenced by the following data type Delete field: ALTER TABLE [table na
operators to compare the column values of the concatenated columns. There are three types of internal connections:1. Equivalent connection: Use the equals sign (=) operator in the join condition to compare the column values of the joined columns, and the query results list
Advanced Query Technology involves the link query technology of multiple tables, the subquery technology embedded in SELECT statements, and the joint technology that combines multiple queries.
1. Connection Query
You need to retrieve data from two or more tables at the same time. The link allows you to retrieve data from two or more tables at the same time and sp
First is three tables, CNO corresponds to the course, where I pasted.
Primary table
Name list
Follow the general query
SELECT S.sname, C.cname,s2. Scgrade
From S INNER JOIN SC s2 on S2. SNo = S.sno INNER JOIN c c on c.cno = s2. CNo
So the result is this.
But this is not the result I want to see.
We want to see this result:
So what do we do?The first method of writing:
Copy Code code
statement)---Inarithmetic subquerySELECT * | field name [, field Name 2, ...] from data table name where conditional expression in (SELECT * | field name [, field Name 2, ...] from data table name [where condition expression])Cases:Use Commodity Management databaseGoSelect customer name, contact phone from Customer information table where customer number in (sel
), variable length, can hold photos, files, etc.
int, integer field. Example: Userage int
float, floating-point data is approximate. Example: Userresults float, the approximate numeric data type used to represent floating-point numeric data.
datetime, Date type. Example: Createdatetime datetime
Bit, Boolean type. Can be set to True is male, false is schoolgirl
If the content is very much, indeterminate length (such as article), can be used: nvarchar (max) 6. Save the
), variable length, can hold photos, files, etc.
int, integer field. Example: Userage int
float, floating-point data is approximate. Example: Userresults float, the approximate numeric data type used to represent floating-point numeric data.
datetime, Date type. Example: Createdatetime datetime
Bit, Boolean type. Can be set to True is male, false is schoolgirl
If the content is very much, indeterminate length (such as article), can be used: nvarchar (max) 6. Save the
databaseSysindexs each database indexSysmenbers each database role memberSysobjects all database objects in each databaseSyspermissions permissions for each databaseSystypes user-defined data types for each databaseSysusers each database user
//How can I obtain all the column names in a table. SQL statement.Select column name = name from syscolumns where id = object_id (n' name of the
Tags: reading Notes database sql Part iii:thinking in SetsCHAPTER7 Thinking in Sets The three Mostcommon set operations is as follows.
Intersection
Difference
Union
in the SQL The corresponding keywords in each of the
Intersection
Except
Union
The actual database implementation generally supports the following
Tags: on as SQL type Oracle table text class ROMQuery all columns and their properties for a table:Select From User_tab_columns t,user_col_comments Cwhere t.table_name = c.table_name and T.column_name = c.column_name and t.table_name = women;To find the primary key for a table:Find the foreign key of the table (incl
subqueries, multiple table queries, federated queriesThese three concepts are interpreted slightly differently in different versions of SQL, roughly as follows:
Join connectionCan look at the relevant SQL information, or buy a book of SQL
1, such as: SELECT * from TAB1 where ID in (SELECT id form tab2 where ...)The
SQL subquery, multi-Table query, and joint Query
Subquery, multi-Table query, and joint QueryThese three concepts are interpreted slightly differently in different SQL versions, roughl
Select A.name as table name, b.name as column name, c.name as type, b.max_length as Byte count, b.precision As Integer, B.scale as decimal from Sys.tables a INNER JOIN Sys.columns B on a.object_id=b.object_id inner join Sys. Types C on c.user_type_id=b.user_type_idThis article is from the "IT" blog, so be sure to keep this source http://8577754.blog.51cto.com/8567754/1553205How to use a statement in an SQL
Existing tables table1 and table2, table structure table1: table2: The purpose is to query from table1 that all stus are 0, and all records corresponding to fid contained in the fids field of table 2. The SQL statement is as follows: select * fromtable1whereexists (selectfidfromtable2wherestus0
Existing tables table1
Dear friends, I am a little Cainiao. In practice, I found a statement similar to the following: {code ...} $ sid indicates the value passed from the front end. seller_item_classify indicates that the sid indicates a field name in the table. if the value passed by $ sid is exactly #039; sid #039; the SQL w... dear friends, I am a little Cainiao. In practice, I found that the statement is similar to the fol
Table:Reseller Dealer Field UID Parent_uid nameContact Contacts Field UID dealer_id contact_mainDemand:Want to inquire about the reseller's information, and the main contact information of this reseller, and the reseller's parent reseller's nameCaseThere may be parent_id that are nullSQL statements: SELECT dea.uid uid, dea.enabled_flag enabledflag, dea.delete_flag Deleteflag, dea.tenement_id Tenementid, dea.parent_id parentid, pd.name parentname,
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.