Solved

Concat in Select for Search Return

Posted on 2011-03-13
6
285 Views
Last Modified: 2012-06-22
I am working on an auto suggest and I would like people to be able to either type in a product number or product name.  So for example

If they start to type 1234 it will start to show the products

12345: The Product 1
12346: The Product 2

Or if they type in Product
It would show the same results


So how can i can I concatenate the product id and product name in a query and have it format like that, even with the colon in it?
0
Comment
Question by:theideabulb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 35121422
what is the problem?
* building the query?
* shoing the data
* running the query as users type?
please clarify...

in mysql, to concat, it would be:
 select concat(product_id, ': ' , product_name from products where product_id like '%$user_input%' or product_name like '%$user_input%'

Open in new window

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html

hope this helps
0
 

Author Comment

by:theideabulb
ID: 35121426
if i am doing an autosuggest, would i still need to do the two LIKE statements, if you are combining them and use an alias

 select concat(product_id, ': ' , product_name as theProduct

could you just search it as one string?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35121443
you could. ... but it would be as inefficient as doing the "or" as I showed (because of the LIKE '% ... %' part) ...
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

Author Comment

by:theideabulb
ID: 35121444
so this wouldn't be a good way to do it?

SELECT set_id, CONCAT(product_number,': ',product_name) as theProduct FROM products
having lower(theProduct) like  '%1234%'
0
 

Author Closing Comment

by:theideabulb
ID: 35121457
Thank you for your help.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35121466
from what I know, you could not even do that in terms of syntax (you cannot use the alias except in the ORDER BY)
also, using HAVING only makes sense in GROUP BY queries ...
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
category table 2 43
MySQL Error Code 2 31
mysql to shows result of all other id in another colunm if id select in table 3 48
Delete image(s) associated with record(s) 16 46
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question