Search where concat name after select in mysql queryHow do I quickly rename a MySQL database (change schema name)?Using mysql concat() in WHERE clause?How to output MySQL query results in CSV format?MySQL “NOT IN” queryMySQL select with CONCAT conditionMySQL CONCAT(“string”,longtext) results in hex stringHow to search for a full name when first name and last name are stored in a different columnsYii2 Gridview merge two columnsMysql Concat two columns while searching with LIKEDjango Queryset for concat query fullname of first_name and last_name

How to befriend someone who doesn't like to talk?

C++ logging library

Is Jesus the last Prophet?

Suppose leased car is totalled: what are financial implications?

Part of my house is inexplicably gone

A life of PhD: is it feasible?

When to use и or а as “and”?

How to show a "node near coord" even when it is out of bounds (with clip = true)?

Parsing text written the millitext font

What is the STRONGEST end-of-line knot to use if you want to use a steel-thimble at the end, so that you've got a steel-eyelet at the end of the line?

Why do the TIE Fighter pilot helmets have similar ridges as the rebels?

What does the homotopy coherent nerve do to spaces of enriched functors?

How to avoid typing 'git' at the begining of every Git command

Why does there seem to be an extreme lack of public trashcans in Taiwan?

Entered UK using my now-lost UK passport; can I go to Spain using my US passport?

What to bootstrap for hypothesis testing

Grandpa has another non math question

Can I use 220 V outlets on a 15 ampere breaker and wire it up as 110 V?

How many sets of dice do I need for D&D?

Why do (or did, until very recently) aircraft transponders wait to be interrogated before broadcasting beacon signals?

Make Gimbap cutter

In The Incredibles 2, why does Screenslaver's name use a pun on something that doesn't exist in the 1950s pastiche?

What is the theme of analysis?

Oil draining out shortly after turbo hose detached/broke



Search where concat name after select in mysql query


How do I quickly rename a MySQL database (change schema name)?Using mysql concat() in WHERE clause?How to output MySQL query results in CSV format?MySQL “NOT IN” queryMySQL select with CONCAT conditionMySQL CONCAT(“string”,longtext) results in hex stringHow to search for a full name when first name and last name are stored in a different columnsYii2 Gridview merge two columnsMysql Concat two columns while searching with LIKEDjango Queryset for concat query fullname of first_name and last_name






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have a table with several columns generated from a mysql query. One is merged using concat 'first_name' and 'last_name' making the column 'username'. All the columns can be individualy filtered.



So I was wondering if a concat value could be filtered after it has been selected in a query. So something like...



->selectRaw('CONCAT(first_name, " ", last_name) AS username')
->where('username', 'LIKE', '%search_username%')


I understand I could do something like.



->where(DB::raw("CONCAT(first_name, " ", last_name) LIKE '%search_username%")


But I have done a loop which goes through all the search columns and differentiates between a column name or concat value.



foreach ($search->filters as $key => $value) 
// Check for column search
if($value->type === 'column')
$query->where($value->name, 'LIKE', "%$value->text%");

// Check for concat search
if($value->type === 'concat')
$query->where(?);











share|improve this question






















  • If you end up doing SQL in loops you're probably doing the wrong thing. A generated column being the CONCAT. Potentially use a FT index rather rthan LIKE '%xx%. FT search engines like Solr, Sphinx, Lucene do searches better than MySQL.

    – danblack
    Mar 25 at 0:47

















0















I have a table with several columns generated from a mysql query. One is merged using concat 'first_name' and 'last_name' making the column 'username'. All the columns can be individualy filtered.



So I was wondering if a concat value could be filtered after it has been selected in a query. So something like...



->selectRaw('CONCAT(first_name, " ", last_name) AS username')
->where('username', 'LIKE', '%search_username%')


I understand I could do something like.



->where(DB::raw("CONCAT(first_name, " ", last_name) LIKE '%search_username%")


But I have done a loop which goes through all the search columns and differentiates between a column name or concat value.



foreach ($search->filters as $key => $value) 
// Check for column search
if($value->type === 'column')
$query->where($value->name, 'LIKE', "%$value->text%");

// Check for concat search
if($value->type === 'concat')
$query->where(?);











share|improve this question






















  • If you end up doing SQL in loops you're probably doing the wrong thing. A generated column being the CONCAT. Potentially use a FT index rather rthan LIKE '%xx%. FT search engines like Solr, Sphinx, Lucene do searches better than MySQL.

    – danblack
    Mar 25 at 0:47













0












0








0








I have a table with several columns generated from a mysql query. One is merged using concat 'first_name' and 'last_name' making the column 'username'. All the columns can be individualy filtered.



So I was wondering if a concat value could be filtered after it has been selected in a query. So something like...



->selectRaw('CONCAT(first_name, " ", last_name) AS username')
->where('username', 'LIKE', '%search_username%')


I understand I could do something like.



->where(DB::raw("CONCAT(first_name, " ", last_name) LIKE '%search_username%")


But I have done a loop which goes through all the search columns and differentiates between a column name or concat value.



foreach ($search->filters as $key => $value) 
// Check for column search
if($value->type === 'column')
$query->where($value->name, 'LIKE', "%$value->text%");

// Check for concat search
if($value->type === 'concat')
$query->where(?);











share|improve this question














I have a table with several columns generated from a mysql query. One is merged using concat 'first_name' and 'last_name' making the column 'username'. All the columns can be individualy filtered.



So I was wondering if a concat value could be filtered after it has been selected in a query. So something like...



->selectRaw('CONCAT(first_name, " ", last_name) AS username')
->where('username', 'LIKE', '%search_username%')


I understand I could do something like.



->where(DB::raw("CONCAT(first_name, " ", last_name) LIKE '%search_username%")


But I have done a loop which goes through all the search columns and differentiates between a column name or concat value.



foreach ($search->filters as $key => $value) 
// Check for column search
if($value->type === 'column')
$query->where($value->name, 'LIKE', "%$value->text%");

// Check for concat search
if($value->type === 'concat')
$query->where(?);








mysql where concat






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 24 at 22:54









PaulPaul

385




385












  • If you end up doing SQL in loops you're probably doing the wrong thing. A generated column being the CONCAT. Potentially use a FT index rather rthan LIKE '%xx%. FT search engines like Solr, Sphinx, Lucene do searches better than MySQL.

    – danblack
    Mar 25 at 0:47

















  • If you end up doing SQL in loops you're probably doing the wrong thing. A generated column being the CONCAT. Potentially use a FT index rather rthan LIKE '%xx%. FT search engines like Solr, Sphinx, Lucene do searches better than MySQL.

    – danblack
    Mar 25 at 0:47
















If you end up doing SQL in loops you're probably doing the wrong thing. A generated column being the CONCAT. Potentially use a FT index rather rthan LIKE '%xx%. FT search engines like Solr, Sphinx, Lucene do searches better than MySQL.

– danblack
Mar 25 at 0:47





If you end up doing SQL in loops you're probably doing the wrong thing. A generated column being the CONCAT. Potentially use a FT index rather rthan LIKE '%xx%. FT search engines like Solr, Sphinx, Lucene do searches better than MySQL.

– danblack
Mar 25 at 0:47












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55329367%2fsearch-where-concat-name-after-select-in-mysql-query%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55329367%2fsearch-where-concat-name-after-select-in-mysql-query%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript