あるテーブルからレコードを選択して別のテーブルからレコードを除外します
質問:
2 つのテーブルがあり、table1 に列 ID と名前が含まれ、table2 に列 ID と名前が含まれている場合、名前の値が table1 にない table2 内のすべての行を取得します。
推奨クエリ (間違っています):
SELECT name FROM table2 -- that are not in table1 already
解決策:
望ましい結果を取得するためのより正確なクエリは次のとおりです:
SELECT t2.name FROM table2 t2 LEFT JOIN table1 t1 ON t1.name = t2.name WHERE t1.name IS NULL;
説明:
このクエリは、左結合を使用して、名前列に基づいて table2 の各行を table1 の対応する行と照合します。 table1 に一致する行が見つからない場合、結果内のその行の t1.name 値は NULL になります。 t1.name が NULL である行のみを選択することで、table1 の名前値と一致する table2 のレコードを効果的に除外します。 あるいは、NOT EXISTS
句を使用して同じ結果を得ることができます:
SELECT name FROM table2 t2 WHERE NOT EXISTS ( SELECT 1 FROM table1 t1 WHERE t1.name = t2.name );
NOT EXISTS
バージョンは、一般に、特に大規模なデータセットの場合、LEFT JOIN
バージョンよりも効率的です。
以上がTable1 と一致する名前を持つレコードを除外して Table2 からレコードを選択するにはどうすればよいですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

todropaviewinmysql、 "dropviewifexistsview_name;" andtomodifyaviewを使用して、 "createorreplaceviewview_nameasselect ..."を使用します

mysqlviewscanefectiveativeativeizedesignpatternslikeadapter、decorator、factory、andobserver.1)adapterpatternadaptsdatafromdifferenttablesintoaunifiedview.2)decoratorpatternenhancesdatawithedfieldsfieldsiffieldsiffieldsiffiedを

viewsinmysqlarebenefentialforsimprifiningcomplexqueries、拡張セキュリティ、ダタコンシーニング、および最適化されたパフォーマンスを保証する1)itsmplifyififycomplexqueriesbyencapsulsingthemintoreusableviews.2)viewsencurationecuritybycontrollingcescesces.3)

to CreateAsimpleviewinmysql、usethecreateviewstatement.1)DefinetheTheTheThecreateview_nameas.2)SpecifyTheSelectStatementtatementtatementtatementtatementtatementtatementedeSireddata.3)

tocleateusersinmysql、usethecreateuserstatement.1)foralocaluser:createUser'localuser '@' localhost'identifidedifiedifiedified 'securepassword';

mysqlviewshavelimitations:1)supportallsqloperations、制限、dataManipulationswithjoinsorubqueries.2)それらは、特にパフォーマンス、特にパルフェクソルラージャターセット

reperusermanmanagementInmysqliscialforenhancingsecurationsinginuring databaseaperation.1)usecreateusertoaddusers、指定connectionsourcewith@'localhost'or@'% '。

mysqldoes notimposeahardlimitontriggers、しかしpracticalfactorsdeTerminetheireffectiveuse:1)serverconufigurationStriggermanagement; 2)complentiggersincreaseSystemload;


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

WebStorm Mac版
便利なJavaScript開発ツール

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン

MinGW - Minimalist GNU for Windows
このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。

SublimeText3 中国語版
中国語版、とても使いやすい

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)
