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 192051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:23:36+00:00 2026-05-11T16:23:36+00:00

Have a problem that seems easy on paper but i’m having a big problem

  • 0

Have a problem that seems easy on paper but i’m having a big problem figuring out how best to write a single query.

I have a table

CREATE TABLE `profile_values` (  
  `fid` int(10) unsigned NOT NULL default '0',  
  `uid` int(10) unsigned NOT NULL default '0',  
  `value` text,  
  PRIMARY KEY  (`uid`,`fid`),  
  KEY `fid` (`fid`)  
) 

The point of this table is to store profile information on a user.
E.g. a typically row would look like this..

fid | uid | value  
__________________
1   | 77  | Mary  
11  | 77  | Poppins  
1   | 123 | Steve  
11  | 123 | Davis  

Note:

'fid' of '1' represents the first name  
'fid' of '11' represents the last name  
'uid' is a users id within the site.  

What I am trying to achieve is to bring back all uid’s that satisfy the condition of first name like ‘S%’ and last name like ‘D%’.
The reason i need this is because i have an autocomplete search box for users on the site.
So if i type ‘S’ in the search box i will see list of all users that begin with the letter ‘S’, if i now type a whitespace and ‘D’ i should now be able to see the list of users who match both conditions.

Does anyone have any idea how this can be accomplished?
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-05-11T16:23:36+00:00Added an answer on May 11, 2026 at 4:23 pm
    select firstname.uid, fistname.value, lastname.value
    from 
      profile_values firstname
      inner join profile_values lastname 
        on firstname.uid = lastname.uid
    WHERE
      firstname.fid = 1
      AND lastname.fid = 11
      AND fistname.value like 'S%'
      AND lastname.value like 'D%'
    

    or, with a users table

    select users.uid, fistname.value, lastname.value
    from 
      users
      inner join profile_values firstname
        on firstname.uid = users.uid
        AND firstname.fid = 1   
      inner join profile_values lastname 
        on lastname.uid = users.uid
        AND lastname.fid = 11
    WHERE
      fistname.value like 'S%'
      AND lastname.value like 'D%'
    

    EDIT:

    Forgot to mention: union performs bad on many dbms. If you need a union, there is mostly something wrong with your database model. Use any other alternative before using union.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 97k
  • Answers 97k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think you have more flexibility if you construct your… May 11, 2026 at 7:23 pm
  • Editorial Team
    Editorial Team added an answer After some quick experimentation, I figured out that you need… May 11, 2026 at 7:23 pm
  • Editorial Team
    Editorial Team added an answer It always bugs me that these error messages don't tell… May 11, 2026 at 7:23 pm

Related Questions

I have a bunch of pretty large CSV (comma separated values) files and I
The other day I set up an Ubuntu installation in a VM and went
I have a java back-end that needs to expose services to clients running in
I'm working on a multithreaded C++ application that is corrupting the heap. The usual
I've been running up against a problem with Java Swing + my Wacom Graphire

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.