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
-- Process duplicate table records (query and delete)
/*************************************** **************************************** **************************************** *******************************
1. Repeat records with the same num and name. Only one record is retained if there is no size relationship.
2. if the name is the same and the ID has a size relationship, keep one of the records large
A.TargetPeriod like '%123%' and E.OrgCode like '%123%'order by A.TargetPeriod desc,C.SalesName,D.CatalogName
The preceding SQL statement contains some special cases, such as the Convert function, no primary key, multi-table join, table alias, and field alias. These cases may be tricky to handle, of course, the "'' as CheckBox "is a special case in my system and
Tags: _id repos query Statement automatic learning experience query logs SQL definitionFirst, in the @entity annotated class to write a good foreign key relationship.This @ManyToOne annotation can establish a foreign key relationship, not in their own silly write a private int grades_id; After writing this note, it automatically adds the Classes
, the number of rows in the result set is equal to the number of rows that meet the query conditions in the first table multiplied by the number of rows that meet the query conditions in the second table. The ON (join_condition) clause in the Join Operation specifies the join condition, which consists of
Today, I spoke a multi-table query and a subquery for SQLThere are many useful pictures in the notes, it is important to understand the external connection and inner connection, as well as self-connection ... It doesn't show up here, so put a link,to the Youdao cloud notes to see: Http://note.youdao.com/share/?id=90f107b6a6aac379a795373f7f98c6fftype=note
What is the relationship between a multi-
SQL query skills two ways to query whether a table exists
Method 1: Determine whether a system object existsDeclare
@ Dbtablefilename varchar (100)
Set @ dbtablefilename = 'tx'
If objectproperty (object_id (@ dbtablefilename), 'isusertable') is not null
Print 'exists'
Else
Print 'not exists'
If object_id (@ dbtablef
following commands in the query Analyzer:
1. External Connection1. Concept: including left Outer Join, right Outer Join or complete external join
2. Left join: left join or left Outer Join(1) The result set of the left Outer Join includes all rows in the left table specified in the left outer clause, not just the rows matched by the join column. If a row in the left ta
following commands in the query Analyzer:
1. External Connection1. Concept: including left Outer Join, right Outer Join or complete external join
2. left join: left join or left outer join(1) The result set of the left outer Join includes all rows in the LEFT table specified in the left outer clause, not just the rows matched by the join column. If a row in the left ta
Label:There is a business scenario where a single piece of data in the main table has multiple detail data in the child table. When the data is displayed, the product wants to be free to take a sub-table of data associated with the display, with a lot of solutions, but not good enough. SQL
Label:SELECT * FROM (SELECT Tt.*,rownum RN from(SELECTa.case_id as Treatid,A.type as TYPE,B.content as CONTENT,b.add_user_id as Adduserid,B.add_user_type as Addusertrpe,A.create_time as Createtime,B.check_time as Checktime,E.addusertypeFrom T_medical_case ALeft JOIN t_treatment B on a.case_id = b.treat_idLeft JOIN (select c.patient_id as ID, C.user_name, ' 2 ' as AddusertypeFrom T_patient_info CUNIONSelect d.doctor_id as ID, D.user_name, ' 1 ' as AddusertypeFrom T_doctor_info D) E on b.add_user_
The following is an example:Two tables, SourceTable and TargetTable, are logon tables. If the user accesses the login table, update the authorization level of the authorization table. Otherwise, authorization 0 indicates the visitor. The SQL statement is as follows:-- SourceTable: logon table, TargetTable: Authorizatio
the first table with all records of the second table once and back, is useful when generating a test database, for example, you define 7 last names, 7 names, and then cross-connect to generate 49 records. If you have the following table: Last Name table Name table:
In the case of a large record, the not in query will certainly be slow and unacceptable. Like what:SELECT A.* fromWHERE A.user_id not in (SELECT B.user_id from Table_b)the best way to find it now is to check it in seconds. For example, query the DEPT_ID data with table A and b not available:SELECT A.*from tb_dept A, Tb_dept_lev BWHERE= b.dept_id (+) and is NU
Tags: lock table Database unlockBefore the operation of the program, the sudden occurrence of the page card dead, the background does not error, after troubleshooting is the database table is locked dead, the following SQL is the query is locked table, as well as the corresp
same as the result shown in the inner join.
Four, two-table relationship is One-to-many, one-to-many or Many-to-many connection statement
Of course the above two tables are one-to-one, so if Table A and table B are one-to-many, One-to-many, or many-to-many, how do we write connected SQL statements?
In fact, two mor
number =A. Employee number)Note: this should be done to find out the maximum value of each employee's order amount, along with the information of the employee's corresponding order.Many people do this:SELECT * from order form where amount in (select Max (amount) from order Form group by employee number)This practice is wrong.3.6 quantifier QueryCommonly used quantifiers any, all, and some, where any and some are synonyms, as long as the subquery has a true, true, and all of the behavior in the
Tags: tar create done Project class User A mat statusReference: https://bbs.csdn.net/topics/330032307There is a dictionary table in the database, which contains the ID field and the corresponding name fields.In another record table, there is a corresponding ID for the dictionary table above, and there are multiple fields that contain the ID field. It needs to be
Tags: style time span stat name not sel tab DUPI'm using a statement to save the queried data to a new table 1) using the into table statement, the new table that needs to be saved does not need to be created in advance Select * to from table-Insert new Table statement in
In SQL ServerEach database has a table generated by the system.The table sysobjects records all the table names in the database.We can use the following SQL syntax for query operations.
Copy codeThe Code is as follows:Select Name
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.