เราสามารถใช้ฟังก์ชัน FIELD() เพื่อหาตำแหน่งดัชนีของสตริงที่จัดเก็บเป็นระเบียนในคอลัมน์ตาราง MySQL เพื่อสาธิต เราใช้ตารางชื่อ 'websites' ที่มีข้อมูลดังนี้
ตัวอย่าง
mysql> Select * from websites; +----+---------------+------------------------+ | Id | Purpose | Webaddress | +----+---------------+------------------------+ | 1 | For tutorials | www.tutorialspoint.com | | 2 | For searching | www.google.co.in | | 3 | For email | www.gmail.com | +----+---------------+------------------------+ 3 rows in set (0.00 sec)
ตอนนี้ สมมติว่าถ้าเราต้องการหาหมายเลขดัชนีของสตริงเฉพาะ เช่น 'for email' จากสตริงที่จัดเก็บเป็นระเบียนในคอลัมน์ 'Purpose' และ 'Webaddress' ของตารางนี้ คำสั่งต่อไปนี้จะทำได้
mysql> Select FIELD('For email', purpose, webaddress) From websites;
+----------------------------------------+
| FIELD('For email', purpose, webaddress)|
+----------------------------------------+
| 0 |
| 0 |
| 1 |
+----------------------------------------+
3 rows in set (0.00 sec)
ชุดผลลัพธ์ข้างต้นแสดงว่า 'For email' อยู่ที่ดัชนีแรกของแถวที่สาม
mysql> Select FIELD('www.tutorialspoint.com', purpose, webaddress) From websites;
+------------------------------------------------------+
| FIELD('www.tutorialspoint.com', purpose, webaddress) |
+------------------------------------------------------+
| 2 |
| 0 |
| 0 |
+------------------------------------------------------+
3 rows in set (0.00 sec)
ชุดผลลัพธ์ข้างต้นแสดงว่า 'www.tutorialspoint.com' อยู่ที่ดัชนีที่สองของแถวแรก