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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:26:56+00:00 2026-05-25T00:26:56+00:00

I have a little SQL but I can’t find the way to get back

  • 0

I have a little SQL but I can’t find the way to get back text just numbers. – revised!

SELECT if( `linktype` = "group", 

(SELECT contactgroups.grname
FROM contactgroups, groupmembers
WHERE contactgroups.id = groupmembers.id ???
AND contactgroups.id = groupmembers.link_id),

(SELECT contactmain.contact_sur
FROM contactmain, groupmembers
WHERE contactmain.id = groupmembers.id ???
AND contactmain.id = groupmembers.link_id) ) AS adat

FROM groupmembers;

As now I have improved a bit gives back some info but ??? (thanks to minitech) indicate my problem. I can’t see how could I fix… Any advice welcomed! Thansk

Contactmain (id, contact_sur, email2)

data:
1 | Peter | email@email.com
2 | Andrew| email2@email.com

Contactgroups (id, grname)

data:
1 | All
2 | Trustee
3 | Comitee

Groupmembers (id, group_id, linktype, link_id) 

data:
1 | 1 | contact | 1
2 | 1 | contact | 2
3 | 2 | contact | 1
4 | 3 | group   | 2

And I would like to list out who is in the ‘Comitee’ the result should be Andrew and Trustee if I am right:)

  • 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-25T00:26:57+00:00Added an answer on May 25, 2026 at 12:26 am

    It does look a bit redundant on the join since you are implying both the ID and Link_ID columns are the same value. Since BOTH select values are derived from a qualification to the group members table, I have restructured the query to use THAT as the primary table and do a LEFT JOIN to each of the other tables, anticipating from your query that the link should be found from ONE or the OTHER tables. So, with each respective LEFT JOIN, you will go through the GroupMembers table only ONCE. Now, your IF(). Since the group members is the basis, and we have BOTH tables available and linked, we just grab the column from one table vs the other respectively. I’ve included the “linktype” too just for reference purposes. By using the STRAIGHT_JOIN will help the engine from trying to change the interpretation of how to join the tables.

    SELECT STRAIGHT_JOIN
          gm.linktype,
          if( gm.linktype = "group", cg.grname, cm.contact_sur ) ADat
       from
          groupmembers gm
             left join contactgroups cg
                ON gm.link_id = cg.id
             left join contactmain cm
                ON gm.link_id = cm.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a strong database background but very little practical experience with ms sql
I've worked extensively with SQL Server but have very little experience with Oracle. I've
I have a stupid little SQL query which isn't working and i can't figure
Need a little help with a SQL / ActiveRecord query. Let's say I have
I have little knowledge of Flash but for a little Flash game I have
I have little bit longer question for you - but hope answer will be
I have this simple little batch file program that I wrote but it fails
I'm a little new to SQL and have come across the following problem. I
I’ve been trying to get this to work for a while but can’t (I
I have a little DB challenge for you. Hopefully you can help. The Problem:

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.