Mysql common statements
Select * from db_user where user_type in (5, 8); select * from db_user where user_type between (5, 8); select * from db_user where user_name like '% s % '; <span style = "font-family: Arial, Helvetica, sans-serif; ">" % "can match one or more characters </span> select * from db_user where user_name like '_ 3 _'; <span style =" font-family: arial, Helvetica, sans-serif; ">" _ "matches a character </span> select * from db_user where user_name = a or password = 3; // or keyword, match one.
select *from db_user order by id desc;
<Span style = "font-family: Arial, Helvetica, sans-serif; "> </span> <pre name =" code "class =" SQL "> select * from db_user order by id asc; // ascending
Select id, user_name, password group by user_type; // only one record is displayed in each group.
Select * from db_user order by id asc limit 3; // only three records are displayed.
Select * from db_user order by id asc limit 1, 2. query two records from the beginning of the number
<P> select count (*) from db_user; // display the number of all rows </p> <p> select * from user_name, user_type from tp_user, db_user here tp_user.id = db_user.id; // for internal join query, connect two tables </p> <p> select * from tp_user where user_name in (select user_name from db_user ); // query records with the same user_name as db_user in tp_user </p> <p> select * from tp_user where money >=( select money from db_user where id = 1 ); // query method of comparison operators </p> <p> select * from tp_user where user_name like '% php % '; // query records containing php fields </p> <p> select Max (score) from tp_user; // query the records with the highest socret value </p> <p> select * from tp_user where money <ANY (select money from db_user); // query records with the money value less than all db_users, the section in the brackets is called the internal query, and the external called external query </p> <span style = "font-family: monospace; white-space: pre; background-color: rgb (240,240,240); "> select * from tp_user where money> ALL (select money from db_user ); // money is greater than all db_users </span> </p> <span style = "font-family: monospace; white-space: pre; background-color: rgb (240,240,240); "> select user_name from tp_user UNION select user_name from db_user; // merge duplicate user_name </span> </p> <span style = "font-family: monospace; white-space: pre; background-color: rgb (240,240,240); "> <span style =" font-family: monospace; white-space: pre; background-color: rgb (240,240,240 ); "> select user_name from tp_user union all select user_name from db_user; // lists ALL results, not merged </span> </p> <p> // Regular Expression </p> <p> select books from tp_book where books REGEXP '^ php '/ /^ match records starting with a specific character or string </p> <span style = "font-family: monospace; white-space: pre; background-color: rgb (240,240,240); "> select books from tp_book where books REGEXP 'php $ '; // $ match records ending with a specified name </span> </p> <span style = "font-family: monospace; white-space: pre; background-color: rgb (240,240,240); "> <span style =" font-family: monospace; white-space: pre; background-color: rgb (240,240,240 ); "> select books from tp_book where books REGEXP '. P ';//. match the character set and any character, including line breaks and carriage returns </span> </p> <span style = "font-family: monospace; white-space: pre; background-color: rgb (240,240,240); "> <span style =" font-family: monospace; white-space: pre; background-color: rgb (240,240,240); "> <span style =" font-family: monospace; white-space: pre; background-color: rgb (240,240,240 ); "> select books from tp_book where books REGEXP '[pca]'; // [pca] match records containing pca </span> </p> <span style = "font-family: monospace; white-space: pre; background-color: rgb (240,240,240); "> select books from tp_book where books REGEXP '[^ c-z]'; // [^] match any character except Character Set combination </span> </p> <span style = "font-family: monospace; white-space: pre; background-color: rgb (240,240,240); "> <span style =" font-family: monospace; white-space: pre; background-color: rgb (240,240,240 ); "> select books from tp_book where books REGEXP 'php | java | c #'; // | equivalent to or matching any string </span> </p> <span style = "font-family: monospace; white-space: pre; background-color: rgb (240,240,240); "> <span style =" font-family: monospace; white-space: pre; background-color: rgb (240,240,240 ); "> <span style =" font-family: monospace; white-space: pre; background-color: rgb (240,240,240 ); "> select books from tp_book where books REGEXP 'J * a'; // A record that matches J characters before, * 0 </span> </p> <span style = "font-family: monospace; white-space: pre; background-color: rgb (240,240,240); "> <span style =" font-family: monospace; white-space: pre; background-color: rgb (240,240,240 ); "> <span style =" font-family: monospace; white-space: pre; background-color: rgb (240,240,240); "> <span style =" font-family: monospace; white-space: pre; background-color: rgb (240,240,240); "> select books from tp_book where books REGEXP 'J + '; // match A records that have appeared before J at least once, + at least one </span> </p> <span style = "font-family: monospace; white-space: pre; background-color: rgb (240,240,240); "> <span style =" font-family: monospace; white-space: pre; background-color: rgb (240,240,240); "> <span style =" font-family: monospace; white-space: pre; background-color: rgb (240,240,240 ); "> <span style =" font-family: monospace; white-space: pre; background-color: rgb (240,240,240); "> <span style =" font-family: monospace; white-space: pre; background-color: rgb (240,240,240); "> select books from tp_book where books REGEXP 'a {3 }'; // match a record with at least three times </span> </p> <span style = "font-family: monospace; white-space: pre; background-color: rgb (240,240,240); "> select books from tp_book where books REGEXP 'a {2, 4 }; // match a character with a record that appears at least twice and at most 4 times </span> </p> <span style = "font-family: monospace; white-space: pre; background-color: rgb (240,240,240); "> <span style =" font-family: monospace; white-space: pre; background-color: rgb (240,240,240); "> <span style =" font-family: monospace; white-space: pre; background-color: rgb (240,240,240 ); "> <span style =" font-family: monospace; white-space: pre; background-color: rgb (240,240,240); "> <span style =" font-family: monospace; white-space: pre; background-color: rgb (240,240,240 ); "> </span> </p> <span style =" font-family: monospace; white-space: pre; background-color: rgb (240,240,240); "> <span style =" font-family: monospace; white-space: pre; background-color: rgb (240,240,240); "> </span> </p>
</pre><pre>