I'm working with an existing database that has first name and last name seperated in the database. I need to create a function that will take one search input and return results. say my database has a structure like....
nameFirst nameLast Joe Smith Joe Jones Joe Brown
How could I, using MySql, take a search input that is say 'Joe Smith' and just get his row? But if I put just 'Joe' in the search field, return them all? Will I need to explode the string with a space? thanks!
SELECT. left(NAME, charindex(' ', NAME) - 1) AS 'FirstName', REVERSE(SUBSTRING(REVERSE(NAME), 1, CHARINDEX(' ', REVERSE(NAME)) - 1)) AS 'LastName'
Try: WHERE SUBSTRING_INDEX(fullname, " ", -1) = 'lastname' (dev.mysql.com/doc/refman/5.5/en/…) Or consider storing the first and last names in separate fields.
In the Search phrase box, enter the search string and if it is not chosen, from the Database drop-down box, select a database to search in. In the search grid, choose tables and views of interest or leave them all checked. To narrow down the MySQL search data scope, select the table, views, numeric, text type, and date columns checkboxes.
MySQL query to display columns name first name, last name as full name in a single column? MySQL query to display columns name first name, last name as full name in a single column? For this, use CONCAT () method in MySQL.
MySQL full-text search Full-text search is a MySQL search technique to search for data in a database. Please note that not all engines support the full-text search feature. Starting from MySQL version 5.6 or higher, the MyISAM and InnoDB storage engines support a full-text search.
Following is the query to concatenate first name and last name to full name − mysql> select concat(FirstName,' ',LastName) AS FullName from DemoTable; This will produce the following output −
SELECT * FROM table WHERE CONCAT( nameFirst, ' ', nameLast ) LIKE '%Joe%'
Be sure to sanitize any user submitted parameters such as "Joe"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With