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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:53:01+00:00 2026-06-13T11:53:01+00:00

I need to look up email preferences for users. This table contains the types

  • 0

I need to look up email preferences for users.

This table contains the types of email a user can receive, broken down by category.

email_preferences_categories

+----------+------------------+------+-----+---------+----------------+
| Field    | Type             | Null | Key | Default | Extra          |
+----------+------------------+------+-----+---------+----------------+
| id       | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| name     | text             | YES  |     | NULL    |                |
| overview | text             | YES  |     | NULL    |                |
+----------+------------------+------+-----+---------+----------------+

This table contains their preference for receiving various types. If they haven’t set their preferences, this table won’t have any rows for them.

email_preferences

+------------+---------------------------------+------+-----+---------+----------------+
| Field      | Type                            | Null | Key | Default | Extra          |
+------------+---------------------------------+------+-----+---------+----------------+
| id         | int(10) unsigned                | NO   | PRI | NULL    | auto_increment |
| user_id    | int(10) unsigned                | NO   |     | NULL    |                |
| name       | text                            | YES  |     | NULL    |                |
| frequency  | enum('Daily','Monthly','None')  | YES  |     | Daily   |                |
+------------+---------------------------------+------+-----+---------+----------------+

I need to construct a MYSQL query that returns the name and frequency corresponding to the email preferences for a given user.

SELECT name, frequency
FROM email_preferences
LEFT JOIN email_preferences_categories using (name)
WHERE user_id = 42

Where I’m having trouble: If the user hasn’t set their preferences, this query doesn’t return any rows. I would like it to return the default of ‘Daily’ for email categories that are missing.

  • 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-13T11:53:02+00:00Added an answer on June 13, 2026 at 11:53 am

    Change LEFT JOIN to RIGHT JOIN.

    ...
    FROM email_preferences
    RIGHT JOIN email_preferences_categories
    ...
    

    Or alternatively you can swap the tables around:

    ...
    FROM email_preferences_categories
    LEFT JOIN email_preferences
    ...
    

    These two options both do the same thing – ensure that you get all rows from email_preferences_categories even if there is no matching row in email_preferences.

    You also need to change the join condition as you already noticed.


    I would like it to return the default of ‘Daily’ for email categories that are missing.

    You can use IFNULL:

    SELECT name, IFNULL(frequency, 'Daily') AS frequency
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to look up a value in a table where a table can
i need to look xsd file for generate code so i need this document
I need to simulate how my application will look when a user is driving
I have about 20 CSV's that all look like this: [email],[fname],[lname],[prefix],[suffix],[fax],[phone],[business],[address1],[address2],[city],[state],[zip],[setdate],[email_type],[start_code] What I've been
I have a database that consists of two tables, which look like this: users
I need to send email notifications to users and I need to allow the
I need a table where to keep imported contacts (emails) by users, something like
Look to identify the user, email, or phone identifier from Android 1.5. I've seen
This seems to be pretty straight forward. I need to send email from some
Scenario: User gives you an email address. Before they can sign up for services,

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.