Jump to content

CONCAT


barney0o0
Go to solution Solved by Barand,

Recommended Posts

Hi, im trying to create a query for search results. The results are formed from two tables that form the full product code (groups.code1.products.codeDX and groups.code1.products.codeSX).

 

What i gave at the mo..

SELECT groups.grid, groups.code1, products.codeDX, products.CodeSX, products.prodid, products.groupid
FROM groups LEFT JOIN products ON groups.grid = products.groupid 
(CONCAT STUFF)
WHERE (op1 LIKE \"%$trimm%\" OR op2 LIKE \"%$trimm%\") GROUP BY groups.grid

Is it possible to create a CONCAT alias 'after' the join, i.e. 

CONCAT (code1, ".", codeDX) AS op1 CONCAT (code1, ".", codeSX) AS op2

Its possible that people search for group.code1 (FRSC) or just the CodeSX/CodeDX (100674) or the full product code (FRSC.100674)...the results are then echo'd by groupid....any ideas, or am i looking at the solution from the wrong perspective. thanks in advance

Link to comment
Share on other sites

  • Solution

You would put it in the SELECT clause. Also note you cannot use aliases in WHERE clauses

SELECT groups.grid
, groups.code1
, products.codeDX
, products.CodeSX
, products.prodid
, products.groupid
, CONCAT (code1, ".", codeDX) AS op1
, CONCAT (code1, ".", codeSX) AS op2
FROM groups LEFT JOIN products ON groups.grid = products.groupid
WHERE (CONCAT(code1, ".", codeDX) LIKE '%$trimm%'
    OR CONCAT(code1, ".", codeSX) LIKE '%$trimm%' )
ORDER BY groups.grid
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.