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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:57:49+00:00 2026-06-09T12:57:49+00:00

This has been asked but I dont quite match existing questions with my case.

  • 0

This has been asked but I dont quite match existing questions with my case.
I have two tables, the first table is credentials with id username and email

and an email-alias table with user-id (which corresponds to credentials.id) and email. Emails in credentials are more often “user.name@domain.com” while in alias they’d be “usern@domain.com”.

All I have now is

SELECT `username` FROM `credentials` WHERE `email` LIKE ?

But the email will not always match if I query with “usern@domain.com”. What I want to do is get the username with one query which would fall back to email-alias and use “usern@domain.com” to get an user-id from there to be used again in credentials to match a username

The pitfall is that the supplied email could be either an aliased one “usern@..” or “user.name@..”

mysql> describe `email-alias`;
+---------+--------------+------+-----+---------+----------------+
| Field   | Type         | Null | Key | Default | Extra          |
+---------+--------------+------+-----+---------+----------------+
| id      | int(11)      | NO   | PRI | NULL    | auto_increment |
| user-id | int(11)      | NO   | UNI | NULL    |                |
| email   | varchar(100) | YES  |     | NULL    |                |
+---------+--------------+------+-----+---------+----------------+


mysql> describe `credentials`;
+-----------------+--------------+------+-----+---------------------+----------------+
| Field           | Type         | Null | Key | Default             | Extra          |
+-----------------+--------------+------+-----+---------------------+----------------+
| id              | int(11)      | NO   | PRI | NULL                | auto_increment |
| username        | varchar(100) | NO   | UNI | NULL                |                |
| email           | varchar(100) | NO   |     | NULL                |                |
+-----------------+--------------+------+-----+---------------------+----------------+
  • 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-06-09T12:57:51+00:00Added an answer on June 9, 2026 at 12:57 pm

    Your question is kind of confusing but I think what you’re trying to do is select username from the first table if the email exists and if it doesn’t select from the 2nd table if it exists. You would use subqueries for that. Hope this helps.

    SELECT `c.username`
    FROM credentials c
    WHERE c.email = 'usern@domain.com' OR c.id = 
    (SELECT `e.user-id` from email-alias e WHERE e.email = "usern@domain.com")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know questions like this have been asked numerous times, but not quite this
I apologize if this has been asked before, but I haven't quite found the
Im sure this has been asked but I have not located it. I have
I know this question has been asked quite a few times, however, I have
This question has been asked before but i still don't understand it fully so
Pretty sure this has been asked already, but I don't know what to search
I apologise if this has been asked before but I can't find the info
I know this has been asked before but all the answers I found didn't
This has been driving me nuts. I hope it's not been asked before but
Ok, I know this has been asked before but after searching I couldn't find

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.