Get a quick grasp of some incredibly sophisticated SQL statements

Source: Internet
Author: User
   subtle "SQL" statements:

Copy table (copy structure only, source table name: A new table name: b)

       
        
         
        Sql:select * into B from a where 1<>1
       
        

  

Copy table (copy data, source table name: A target table name: b)

       
        
         
        Sql:insert into B (A, B, c) select d,e,f from B;
       
        

Show article, submitter, and last reply time

       
        
         
        Sql:select a.title,a.username,b.adddate from Table A,

(select Max (adddate) adddate from table where Table.title=a.ti TLE) b
       
        

Description: Outer join query (table name 1:a table name 2:b)

       
        
         
        Sql:select a.a, A.B, A.C, B.C, B.D, B.f from a left-out JOIN b on a.a = 

B.C
       
        

Schedule five minutes Advance reminder

       
        
         
        Sql:select * from schedule where DateDiff (' minute ', F start time, GETDATE ()) >5
       
        

Two related tables, deleting information that is already not in the secondary table in the primary table

       
        
         
        SQL: 

Delete from info where NOT exists 
(SELECT * from Infobz where Info.infid=infobz.infid)
       
        
1 2 Next page > full text reading tips: Try "←→" button, turn the page more convenient Oh!

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.