Select all where [first letter starts with B]

后端 未结 5 1162
耶瑟儿~
耶瑟儿~ 2020-12-08 06:28

This is a follow up question to my previous one. I want to write a MYSQL statement that echoes every entry that starts with letter B.

Function.php

f         


        
相关标签:
5条回答
  • 2020-12-08 06:36

    Following your comment posted to ceejayoz's answer, two things are messed up a litte:

    1. $first is not an array, it's a string. Replace $first = $first[0] . "%" by $first .= "%". Just for simplicity. (PHP string operators)

    2. The string being compared with LIKE operator should be quoted. Replace LIKE ".$first."") by LIKE '".$first."'"). (MySQL String Comparison Functions)

    0 讨论(0)
  • 2020-12-08 06:38

    You can use:

    WHERE LEFT (name_field, 1) = 'B';
    
    0 讨论(0)
  • 2020-12-08 06:44

    This will work for MYSQL

    SELECT Name FROM Employees WHERE Name REGEXP '^[B].*$'
    

    In this REGEXP stands for regular expression

    and

    this is for T-SQL

    SELECT Name FROM Employees WHERE Name LIKE '[B]%'
    
    0 讨论(0)
  • 2020-12-08 06:49
    SELECT author FROM lyrics WHERE author LIKE 'B%';
    

    Make sure you have an index on author, though!

    0 讨论(0)
  • 2020-12-08 06:57

    SQL Statement:

     SELECT * FROM employee WHERE employeeName LIKE 'A%';
    

    Result:

    Number of Records: 4
    
    employeeID  employeeName    employeeName    Address City    PostalCode  Country
    
    1           Alam             Wipro          Delhi   Delhi   11005      India
    
    2           Aditya           Wipro          Delhi   Delhi   11005      India
    
    3           Alok             HCL            Delhi   Delhi   11005      India
    
    4           Ashok            IBM            Delhi   Delhi   11005      India
    
    0 讨论(0)
提交回复
热议问题