Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8873727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:32:13+00:00 2026-06-14T18:32:13+00:00

UPDATE I solved it my self using: http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_concat-ws I updated the code below if

  • 0

UPDATE

I solved it my self using:
http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_concat-ws

I updated the code below if anyone need to do the same and lands here.

I have a small MySQL database where I’m Searching for users

SELECT *, kunde.id as kundeid
FROM kunde
INNER JOIN $bartype ON ($bartype.brugerid = kunde.id)
WHERE  $bartype.barid ='$barid[Barid]' AND
    (email LIKE '%$keyword%') OR
    (fornavn LIKE '%$keyword%') OR
    (efternavn LIKE '%$keyword%') OR
    (CONCAT_WS(' ', fornavn, efternavn) LIKE '%$keyword%')
LIMIT 0, 50;

Now my search function works, but only for either '%$keyword%' LIKE fornavn or '%$keyword%' LIKE efternavn or '%$keyword%' LIKE email.

So I would like to group the LIKE results so that when searching for “fornavn efternavn” in one string it would still show up results from these 2 columns that are in the same row.

Does this make sense? And is it possible to modify my SQL statement to do this?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:32:14+00:00Added an answer on June 14, 2026 at 6:32 pm

    To do what you would like, you might want to try a UNION statement. A union statement will take results from one query and add it into the results from another query while preserving the order (in my example, results having the email will come first, followed by fornavn, followed by efternavn). Doing it this way will also eliminate your AND/OR logic that might be preventing search results from appearing.

    SELECT *, kunde.id as kundeid
    FROM kunde
    INNER JOIN $bartype ON ($bartype.brugerid = kunde.id)
    WHERE  $bartype.barid ='$barid[Barid]' AND
        email LIKE '%$keyword%'
    UNION ALL
    SELECT *, kunde.id as kundeid
    FROM kunde
    INNER JOIN $bartype ON ($bartype.brugerid = kunde.id)
    WHERE  $bartype.barid ='$barid[Barid]' AND
        fornavn LIKE '%$keyword%'
    UNION ALL
    SELECT *, kunde.id as kundeid
    FROM kunde
    INNER JOIN $bartype ON ($bartype.brugerid = kunde.id)
    WHERE  $bartype.barid ='$barid[Barid]' AND
        efternavn LIKE '%$keyword%'
    

    On a side note, dynamic SQL like this is ripe for SQL injection. May I suggest you to look into PHP PDO

    UPDATE

    After your comment, here is an updated query that may be able to perform both searches at once for you:

    SELECT *, kunde.id as kundeid
    FROM kunde
    INNER JOIN $bartype ON ($bartype.brugerid = kunde.id)
    WHERE  $bartype.barid ='$barid[Barid]' AND
        email LIKE '%$keyword%'
    UNION ALL
    SELECT *, kunde.id as kundeid
    FROM kunde
    INNER JOIN $bartype ON ($bartype.brugerid = kunde.id)
    WHERE  $bartype.barid ='$barid[Barid]' AND
        fornavn + ' ' + efternavn LIKE '%$keyword%'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update 7/17 SOLVED I've updated my code to the Solved version. Original Question I'm
UPDATE: Solved. Thanks BusyMark! EDIT: This is revised based on the answer below from
UPDATE: SOLVED Hi all, i've got it, just save cookie to temp file, and
UPDATE: First problem solved, second one described at the bottom of this post. UPDATE2:
Update II Problem Solved but Why? This has been the biggest headache ever. My
UPDATE The issue is solved, all the code you can see works. Hello! I
Updated Problem solved, I have some design problem here. The directory looks like that:
I'm working on a personal project using WPF with Entity Framework and Self Tracking
update I solved this problem by myself. I put it here for further reference.
Update: part of the problem might have been solved by accessing the data like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.