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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:47:12+00:00 2026-05-22T23:47:12+00:00

So this is a weird one. I have a search for a person that

  • 0

So this is a weird one.

I have a search for a person that exists in the table “profile” and we have people that are allowed to become like a fan of a person. They can favorite them.

[Profile]
[uid, first, last, location]

[Favorite]
[A][B]

The profile table consists of some basic information (more than that but thats all that needs to be displayed) and the favorite table consists of 2 unique ids. A has B as a favorite. (A -> B). From the select results i want to display different messages (like this is your friend group, this is the other results).

SELECT P.firstname, P.lastname, P.location, P.uid, 2 AS type
FROM profile AS P
    JOIN favorites AS F
    ON F.A = 'myid' and F.B = P.uid
WHERE (P.firstname LIKE 'mich%' or P.lastname LIKE 'mich%')  

So this first one gets all of the people that i consider my favorite. Second, how do i get a general result and append it to SUCH THAT there are no duplicate results?

I tried something like this.

SELECT P.firstname, P.lastname, P.location, P.uid, 2 AS fan
FROM profile AS P
    JOIN favorites AS F
    ON F.A = P.uid and F.B = 'myid'
WHERE (P.firstname LIKE 'micha%' or P.lastname LIKE 'micha%')
  UNION
SELECT P.firstname, P.lastname, P.location, P.uid, 1 AS fan
FROM profile AS P
    JOIN favorites AS F
    ON F.A != P.uid and F.B = 'myid'
WHERE (P.firstname LIKE 'micha%' or P.lastname LIKE 'micha%')
  • 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-22T23:47:13+00:00Added an answer on May 22, 2026 at 11:47 pm

    I think you can combine that into one simple query using a case statement and a left join:

    select p.firstname, p.lastname, 
       p.location, p.uid, 
       case when f.A is null then 1
       else 2
           end as type
    from profile as p
    left join favorites as f
     on p.uid = f.B and f.A = 'myid'
    where p.firstname like 'mich%' or p.lastname like 'mich%'
    

    This will search profiles for your WHERE clause, and if it matches your favorites join the type field will evaluate to a 2, otherwise it will be one.

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

Sidebar

Related Questions

This is a weird one for you... I have a search box in my
So I have this website that has a search feature which searches a table
This is a weird one. I have a page that simple_format's a comments attribute
this is a weird one. i have a -pre-compile target in my custom_rules.xml .
Ok, this is a really weird one. I have an MPI program, where each
Ok, this one is weird, i have this code: $('#nps').submit(function(e) { e.preventDefault(); var images
I know this one is the weirdest of all weird questions I have asked
This is a weird one. On and off as I have been working on
Now this is a weird one We have a project where we are reading
A weird one: I have a site using ModX and this morning when I

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.