Get the App
SLTechnology News&Howtos  ›  Database  › 

Whether one field of sql contains another field

Shulou Source: shulou.com Published: 2022-06-01 05:40:06 09月27日 Update

/ * Navicat MySQL Data TransferSource Server: testSource Server Version: 50528Source Host: localhost:3306Source Database: testTarget Server Type: MYSQLTarget Server Version: 50528File Encoding: 65001Date: 2015-03-13 11:25:34*/SET FOREIGN_KEY_CHECKS=0 -Table structure for queryreptycode-- DROP TABLE IF EXISTS `queryreptycode`; CREATE TABLE `queryreptycode` (`id` int (11) NOT NULL, `code` varchar (50) DEFAULT NULL, `codeRepty` varchar (50) DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 -Records of queryreptycode-- INSERT INTO `queryreptycode` VALUES ('1th,' 1th,'1'); INSERT INTO `queryreptycode` VALUES ('2stories,' 2stories, '2partners,' 3countries 4countries'); INSERT INTO `queryreptycode` VALUES ('3stories,' 3cycles,'1 ')

The data are:

Select DISTINCT Q1.idINNER JOINqueryreptycode as Q1.coderection Q1.codeRepty from queryreptycode as Q1 codeRepty Q2 where INSTR (Q1.`code`,'%'+ Q2.codeReptyweights%')

Principle:

The function INSTR tells the user whether one of the strings (parameters) is in another string (also parameters).

The specific syntax format is as follows:

INSTR (string,substring [, start [, occurrence]])

Where:

String string to be queried

The string that substring is searching for

Start indicates the character position at which to start the search. The default value is 1, that is, the search will start with the first character of the string. If the parameter is negative, the location of the search is calculated from the right instead of the default from the left

Occurrence specifies the number of occurrences of the substring you are trying to search for. The default value is 1, which means that you want it to appear for the first time.

This function feeds back an index order value, where the substring to be searched is found. The following example indicates the use of the INSTR function:

INSTR ('AAABAABA','B') = 4

INSTR ('AAABAABA','B',1,2) = 7

Tags: Character search string position function parameter field example principle right that is case data format current user index syntax facet Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Apple Xiaomi macOS Redmi