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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:32:11+00:00 2026-05-27T11:32:11+00:00

I have 3 tables. user id firstname lastname … user_rel_domain user_id domain_id value domain

  • 0

I have 3 tables.

user
    id
    firstname
    lastname
    ...

user_rel_domain
    user_id
    domain_id
    value

domain
    id
    name

I would like to make a search that would match the firstname, the lastname and the domain(s) name(s) if the value in user_rel_domain is higher then 0.

How could I do this in a single MySQL query?

EDIT:

Ok, I though that this idea would be easy to integrate from the 3 tables example, but I actually have 6 tables and I don’t think that the answers can be used for the structure I really have, so here it is, sorry everyone!:

user
    id
    firstname
    lastname
    ...

user_rel_domain
    user_id
    domain_id
    value

domain
    id
    name

user_rel_mandate
    user_id
    mandate_id
    value

mandate
    id
    cat_id
    name

mandate_cat
    id
    name

Basically I want to search in all the “name” columns and the firstname and lastname of the user table while all the value from the relation tables be higher then 0.

  • 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-27T11:32:11+00:00Added an answer on May 27, 2026 at 11:32 am

    EDIT: Hmm… I made a few assumptions about your new requirements, so let me know if this is in the ballpark:

    SELECT
        u.firstName,
        u.lastName,
        d.name AS domainName,
        m.name AS mandateName,
        mc.name AS mandateCatName
    FROM
        user u
        JOIN user_rel_domain urd ON urd.user_id = u.id AND urd.value > 0
        JOIN domain d ON d.id = urd.domain_id
        JOIN user_rel_mandate urm ON urm.user_id = u.id AND urm.value > 0
        JOIN mandate m ON m.id = urm.mandate_id
        JOIN mandate_cat mc ON mc.id = m.cat_id
    WHERE
        u.firstName = @SearchTerm
        OR u.lastName = @SearchTerm
        OR d.Name = @SearchTerm
        OR m.Name = @SearchTerm
        OR mc.Name = @SearchTerm
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 tables: users (id, firstname, lastname, etc) users_to_groups (user_id(index), group_id(index)) I would
I have the following tables TUser (user_id,firstname,lastname) PK user_id TGroup (group_id,name) PK group_id TUsersGroups
I have three tables: User: UserId (pk) FirstName Lastname Messages: MessageId (pk) Heading Body
I have a user table like this FIRSTNAME | LASTNAME | ID | --------------------------------
I have two tables user table user_id | name | 1 | peter |
I have several tables: table user: id firstname lastname 1 John Doe 2 Jane
I have 3 tables: USER ===== USER_ID(PK) FISRT_NAME LAST_NAME ... ROLES ====== ROLE_ID (PK)
I have two tables in my database members (member_id, firstname, lastname) members_photos (member_id, photo_id)
I have created 3 tables: Login(firstname,lastname,age,gender,email) Scraps(email,scrap,posttime) requests(email,frnemail,frnshpstatus,frnpic) I want a query that connects
I have a two separate tables that contain parts of user name (don't ask

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.