Home > Database > Mysql Tutorial > body text

Search two keys in MySQL

PHPz
Release: 2023-09-13 17:25:02
forward
840 people have browsed it

在 MySQL 中搜索两个键

Let us understand how to search two keys in MySQL

With help you can use “OR” to achieve Search for a well-optimized single key or use a well-optimized "AND". Let’s see how to combine two different keys with the “OR” operation to search -

SELECT field1_index, field2_index FROM tableName
WHERE field1_index = '1' OR field2_index = '1'
Copy after login

This is the optimized version of the query. This can also be done efficiently using a "UNION" which combines the output of two separate "SELECT" statements. Each "SELECT" statement searches only one key and can be optimized. Let’s see the actual query -

query

SELECT field1_index, field2_index
FROM tableName WHERE field1_index = '1'
UNION
SELECT field1_index, field2_index
FROM tableName WHERE field2_index = '1';
Copy after login

The above is the detailed content of Search two keys in MySQL. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!