ANY subquery, SOME, ALL keywords, and part of the database query operations skills

1, the first seed queries (comparison operator caused by the sub-query)
Write pictures described here

eg:

select goods_id,goods_name,goods_price from tdb_goods where goods_price >all (select goods_price from tdb_goods where goods_cate='超极本');

2, the second seed query (using [Not] in subquery)
where:
= the any operator in the equivalent.
! = all or <> all operators and not in equivalent.

Notice:
. 1, SET INSERT statement can using a subquery insert (equal sign is because typical comparison operator), while the insert values can not be used subqueries

2, such as query

```
select * from sometable \G;
```

You can get specific delimited data

3, write data query results table

       insert [into] tal_name [(col_name,...)] select ...
           eg: insert into tdb_goods_cates(cate_name) select good_cate from tdb_goods group by goods_cate;

4, multi-table update

update table_references set col_name1={expr1|default}[,col_name2={expr2|default}]...
[where where_condition]

If commodity table is as follows:
Write pictures described here
as well as the classification of products as follows:
Write pictures described here

In view of a need to achieve the two fields goods_cate in FIG cate_name achieve connection updating table
can be implemented with the following code:

update tdb_goods inner join tdb_goods_cates on goods_cate=cate_name set goods_cate=cate_id;

4, create a table and other tables replicate data
eg:

create table tdb_goods_brands(
    brand id smallint unsigned primary key auto_increment,
    brand_name varchar(40) not null
)
select brand_name from tdb_goods group by brand_name;

If the two tables associated with the presence of the same meaning as in Table fields will appear blurred, can not complete the update, this may act to by the alias tables, or in front of a table. Field Name table to indicate the specific operation.

eg:

update tdb_goods as g inner join tdb_goods_brands as b on g.brand_name=b.brand_name set g.brand_name =g.brand_id;  
Released four original articles · won praise 0 · Views 1390

Guess you like

Origin blog.csdn.net/sumtre_w/article/details/53148844