MySQL- Quick Start (6) join query

1, the inner join query: inner join ... on

   Only the records meet the conditions to be able to appear in the result of the relationship, that is exactly equal. Self-join queries is a special inner join query.

2, outer join query:

  1 "left outer connecting / left connecting: Returns all records including records left table and the right table in connection equivalent field.

  2 "right outer connector / Right connection: Returns all records including records left table and the right table in connection equivalent field.

  3 "Full outer join: return all the data records in both tables.

3, sub-queries

  Subquery operators are commonly used: any (some), all, in, exists.

  1》any(some):

select * from t1 where t1.id > any (select id from t2 where t2.name=...)

  2 "all: supra, it can be used with comparison operators.

  3》exists / not exists:

  4》in / not in:

  5 "comparison operator with subqueries: <, <=, =,> = ,! = (Or <>)

  6 "union / union all: consolidated results

4, the regular expression query

  MySQL uses pattern matching characters specified regular expression regexp keyword, the default is not case-sensitive.

  

  Matches the specified string: as long as the string to the query text. If a plurality of strings to be matched between a plurality of strings using separators '|' apart.

select * from test where name regexp 'or|ap';

  Matches the specified string in any one of: a square brackets "[]" to specify a set of characters, wherein only match any character , text that is looking for.

select * from test where name regexp '[orap]';
SELECT * from Test WHERE name regexp '[0-9] | [AZ]' ; // [] may be in the range

  Matching characters other than the specified characters:

select * from test where name regexp '[^a-z0-9]';

  Using {n,} or {n, m} string that specifies the number of consecutive occurrences of:

    {N,}: n times represents at least match the previous character

    {N, m}: indicates that the preceding character matches less than n times, not more than m times.

select * from test where name regexp 'x{2,}';
或者
select * from test where name regexp 'x{2,4}';

5, the data insert, update, delete

   1 "data is inserted:

insert into tb_name(column_list) values (value_list);
或者
insert into tb_name(column_list) values (value_list),(value_list),...;
或者
insert into tb_name values (value_list),(value_list),...;
或者
insert into tb_name(column_list) select (column_list) from tb_name2 where ...;

   2 "to update the data:

update tb_name 
   set column_name = value,...
 where ...;

   3 "delete data:

delete from tb_name [where ...];
TRUNCATE  the Table tb_name; // will delete the original table, and re-create a table

 

Guess you like

Origin www.cnblogs.com/ZeroMZ/p/11456558.html
Recommended