473,321 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Searching by name both in the first name and last name from the database.

111 100+
hii all,
i have aproject where...

wen i enter a text in the textbox..., accordingly it should search in teh first name and last name of the database and display the records

How to search records by name....???


plz some one help me the query...


thnx..
hepsi..
Aug 10 '07 #1
4 2224
henryrhenryr
103 100+
I think you could try a number of approaches. Two I can think of are:

1. Concatenate the two columns:
Expand|Select|Wrap|Line Numbers
  1. SELECT CONCAT(first_name,' ',last_name) AS name FROM table WHERE CONCAT(first_name,' ',last_name) LIKE 'name_entered_in_text_box';
  2.  
NB - if you want exact matches don't use LIKE, just use =. If you want more results, put some wildcards (%) in your LIKE clause (ie LIKE '%henry%').

2. Search each column for the same term:
Expand|Select|Wrap|Line Numbers
  1. SELECT first_name, last_name FROM table WHERE first_name LIKE '%henry%' OR last_name LIKE '%henry%';
  2.  
This will give lots of results as used % before and after and I used OR. Cut the results by using fewer '%' and using AND instead of OR.

Hope that sheds some light on your problem! Good luck!

Henry
Aug 10 '07 #2
rhepsi
111 100+
I think you could try a number of approaches. Two I can think of are:

1. Concatenate the two columns:
Expand|Select|Wrap|Line Numbers
  1. SELECT CONCAT(first_name,' ',last_name) AS name FROM table WHERE CONCAT(first_name,' ',last_name) LIKE 'name_entered_in_text_box';
  2.  
NB - if you want exact matches don't use LIKE, just use =. If you want more results, put some wildcards (%) in your LIKE clause (ie LIKE '%henry%').

2. Search each column for the same term:
Expand|Select|Wrap|Line Numbers
  1. SELECT first_name, last_name FROM table WHERE first_name LIKE '%henry%' OR last_name LIKE '%henry%';
  2.  
This will give lots of results as used % before and after and I used OR. Cut the results by using fewer '%' and using AND instead of OR.

Hope that sheds some light on your problem! Good luck!

Henry

thnx for ur reply...
Aug 28 '07 #3
wish
65
Hi,

If my problem is user input one keyword then i wan to find all the columns in the tables or all the tables in the database?
Eg. table_employee,table_customer,table_product. Each tables got a lot of columns then i wan to find out the similar with the keyword record.

Can someone guide me?

Thanks
Sep 27 '07 #4
r035198x
13,262 8TB
Hi,

If my problem is user input one keyword then i wan to find all the columns in the tables or all the tables in the database?
Eg. table_employee,table_customer,table_product. Each tables got a lot of columns then i wan to find out the similar with the keyword record.

Can someone guide me?

Thanks
Google about how to use LIKE with wildcards.
Sep 27 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Nash Kabbara | last post by:
Hi all, I just finished writing a log reader that reads xml logs (about 1 to 2 MB large). At the command line you can specify the file name, the name of the element and it's value like so:...
14
by: Ludwig77 | last post by:
I read that there are some tags that can be entered in a web page's meta tags in order to prevent web bot searching and indexing of the web page for search engines. What is the tagging that I...
0
by: Jason | last post by:
I would like to be able to place a command button on a primary (parent) form that opens up a subform. I want to use this subform to search for or limit the recordset of data in the primary form. ...
0
by: Jason | last post by:
I would like to be able to place a command button on a primary (parent) form that opens up a subform. I want to use this subform to search for or limit the recordset of data in the primary form. ...
33
by: Geoff Jones | last post by:
Hiya I have a DataTable containing thousands of records. Each record has a primary key field called "ID" and another field called "PRODUCT" I want to retrieve the rows that satisy the following...
11
by: martin DH | last post by:
I have an Access database of employees. Each employee has a unique identification number called "BANNER_ID". Each employee's last name and first name are in the database but are not unique...
3
by: BOMEz | last post by:
Hi all, I'm trying to write up my first SQL database which I would want to be search able. Now currently I can have it search by First Name and Last Name. My code for the search goes like : ...
5
by: lemlimlee | last post by:
hello, this is the task i need to do: For this task, you are to develop a Java program that allows a user to search or sort an array of numbers using an algorithm that the user chooses. The...
1
by: icsnetuk | last post by:
Hi, I have a table called applicants There is a form also called applicants which I use to view / edit the data. On my main dashboard form which is where all of the main options are for the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.