mysqlÖÐ*ÊÇʲôÒâ˼
ÔÚ mysql ÖУ¬* µÄ¼ÄÒå
MySQL ÖеÄÐǺŠ(*) ´ú±í¡°ËùÓС±¡£ÔÚ²î±ðÉÏÏÂÎÄÖУ¬Ëü¾ßÓвî±ðµÄÓ÷¨¡£
1. Ñ¡ÔñËùÓÐÁÐ
ʹÓà * ¿ÉÒÔÑ¡Ôñ±íÖеÄËùÓÐÁУº
SELECT * FROM table_name;
µÇ¼ºó¸´ÖÆ
ËüµÈЧÓÚд³ö±íÖÐËùÓÐÁеÄÃû³Æ£º
SELECT column1, column2, ..., columnN FROM table_name;
µÇ¼ºó¸´ÖÆ
2. Ñ¡ÔñËùÓÐÐÐ
ÔÚ×ÓÅÌÎÊÖУ¬* ¿ÉÓÃÓÚÑ¡ÔñÀ´×ÔÖ÷ÅÌÎʵÄËùÓÐÐУº
SELECT * FROM (SELECT * FROM table_name WHERE condition) AS subquery;
µÇ¼ºó¸´ÖÆ
3. JOIN ±í
ÔÚ JOIN Óï¾äÖУ¬* ¿ÉÓÃÓÚÖ¸¶¨ÅþÁ¬ËùÓÐÐУº
SELECT * FROM table1 JOIN table2 ON table1.id = table2.id;
µÇ¼ºó¸´ÖÆ
4. ͨÅä·û
ÔÚ LIKE ×Ó¾äÖУ¬* ¿ÉÓÃ×÷ͨÅä·û£¬Æ¥Åä 0 ¸ö»ò¶à¸ö×Ö·û£º
SELECT * FROM table_name WHERE name LIKE '%john%';
µÇ¼ºó¸´ÖÆ
Ëü½«Æ¥ÅäÐÕÃûÖаüÀ¨¡°john¡±µÄÈκÎÐС£
5. ÕýÔò±í´ïʽ
ÔÚ REGEXP ×Ó¾äÖУ¬* ¿ÉÓÃ×÷Á¿´Ê£¬Æ¥ÅäÇ°ÃæµÄģʽ 0 ´Î»ò¶à´Î£º
SELECT * FROM table_name WHERE name REGEXP '.*john.*';
µÇ¼ºó¸´ÖÆ
Ëü½«Æ¥ÅäÈκοªÍ·»ò×îºó¶¼ÓС°john¡±µÄÐÕÃû¡£
6. Òþʽת»»
ÔÚijЩÇéÐÎÏ£¬MySQL »á×Ô¶¯½« * ת»»ÎªÆäËûÀàÐÍ¡£ÀýÈ磬ÔÚÊýÖµÉÏÏÂÎÄÖУ¬Ëü½«×ª»»ÎªÊý×Ö£º
SELECT * FROM table_name WHERE id = 10;
µÇ¼ºó¸´ÖÆ
ÕâµÈͬÓÚ£º
SELECT * FROM table_name WHERE id = 10.0;
µÇ¼ºó¸´ÖÆ
×ÜÖ®£¬MySQL ÖеÄÐǺŠ(*) ´ú±í¡°ËùÓС±£¬ÔÚ²î±ðµÄÉÏÏÂÎÄÖоßÓвî±ðµÄ¼ÄÒå¡£Ëüͨ³£ÓÃÓÚÑ¡ÔñËùÓÐÁС¢ÐлòÔÚ JOIN¡¢LIKE ºÍ REGEXP ×Ó¾äÖг䵱ͨÅä·û»òÁ¿´Ê¡£
ÒÔÉϾÍÊÇmysqlÖÐ*ÊÇʲôÒâ˼µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡