The use of InStr functions in MySQL

Source: Internet
Author: User

The use of InStr functions in MySQL

INSTR (field name, String)

This function returns the position of the string in the contents of a field, returns 0 if no string is found, or returns the position (starting at 1)

SELECT * from Tbltopic ORDER by INSTR (Topictitle, ' ha ') > 0 DESC

SELECT INSTR (topictitle, ' ha ') from Tbltopic

Use InStr mates in to sort in MySQL

Sort the instr result as a column, sorted by it

Select id,1 from world_guide where id = 32unionselect * FROM (SELECT ID, InStr (' 30,35,31, ', ' id+ ', ') as D fromworld_blog wher E ID in (30,35,31) Order by D) as t;

Output

+----+---+| ID | 1 |+----+---+| 32 | 1 | | 30 | 1 | | 35 | 4 | | 31 | 7 |+----+---+4 rows in set, 6 warnings (0.02 sec)

Table A
Fields: Names name
Tom
Harry
Table B
Fields: Titles title
Information one three release
Information of the second king released
Information three-sheet three release

Leaderboard, sort by the name of table a like% ' name '% matches the number of the title of Table B

Leaderboard Example

Zhang 32
Wang 51

Select Name, count (b.title) from a inner join B on InStr (b.title,a. Name) >0
Group BY name
Order by Count (B.title)

Select Name, (select COUNT (*) from table B where InStr (title, Table A.name)
From Table A
ORDER BY 2 Desc

The use of InStr functions in MySQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.