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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:05:00+00:00 2026-05-16T15:05:00+00:00

Is there a better way to do this? SELECT subs. * , CASE subs.member_type

  • 0

Is there a better way to do this?

SELECT subs. * ,
       CASE subs.member_type
         WHEN 'member' THEN 
         ( SELECT CONCAT_WS( ' ', members.first_name, members.last_name )
             FROM members
            WHERE members.id = subs.member_id)
         ELSE 
         ( SELECT members_anon.username
             FROM members_anon
            WHERE members_anon.id = subs.member_id)
       END AS fullname,
       CASE subs.member_type
         WHEN 'member' THEN 
         ( SELECT members.email
             FROM members
            WHERE members.id = subs.member_id)
         ELSE 
         ( SELECT members_anon.email
             FROM members_anon
            WHERE members_anon.id = subs.member_id)
       END AS email
  FROM subs
 WHERE subs.item_id =19
   AND subs.item_type = 'blog'
 LIMIT 0 , 30

Ideally I would like to have only one CASE section that returned name and email from the relevant table.

  • 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-16T15:05:00+00:00Added an answer on May 16, 2026 at 3:05 pm

    I would use left outer joins on both tables:

    SELECT subs. * ,
           CASE subs.member_type
             WHEN 'member' THEN CONCAT_WS( ' ', m.first_name, m.last_name )
             ELSE ma.username
           END AS fullname,
           CASE subs.member_type
             WHEN 'member' THEN m.email
             ELSE ma.email
           END AS email
      FROM subs
      LEFT OUTER JOIN members m on (m.id = subs.member_id)
      LEFT OUTER JOIN members_anon ma on (ma.id = subs.member_id)
     WHERE subs.item_id =19
       AND subs.item_type = 'blog'
     LIMIT 0 , 30
    

    Regarding the only one case wish, if you need two different columns on your resultset, you will need two case sentences.

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

Sidebar

Related Questions

Is there a better way of doing this ? SELECT (SELECT count(*) FROM `tbl`
Is there a better way of writing this kind of thing? SELECT * from
Is there a better way of doing a query like this: SELECT COUNT(*) FROM
I have a query that looks like this: SELECT last_name, first_name, middle_initial FROM names
Is there a better way than this to splice an array into another array
Is there a better way than this to determine the row a user double-clicked
Is there a better way to do this? -(NSDate *)getMidnightTommorow { NSCalendarDate *now =
Is there a better way to write this code? I want to show a
Is there a better way to do this? string[] s = {zero, one, two,
Is there a better way of getting this result? This function fails if num

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.