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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:32:24+00:00 2026-05-28T03:32:24+00:00

Summary So I have 3 tables, which I have screenshots below. Every user will

  • 0

Summary

So I have 3 tables, which I have screenshots below. Every user will get 10 slides by default when they sign up, so that information is in the “slides” table. The template_id is just another table I have which is identical to the custom_slides table except there are 10 pre-made slides which are default slides, so if I ever want to update the page name of a default slide, I just do it once in that template table.

If the slide is a custom slide, then template_id will be NULL just like you see for Slide 11, and slide 11 gets put in the custom_slides table.


What I need

So I need help writing a query to get some information. I want to grab the slide_id, the sort_order, and the page_name for a certain user.

So far I have the following:

SELECT slide_id, sort_order FROM `user_slides` WHERE user_id = 1

Now I need to grab the page_name but I need to run a separate query.

  • Check slide_id on the slides table and see if template_id is NULL or has a value.
  • if it has a value then it is a default slide, so if the template_id is 3 then I need to run a query to get the page_name from the templates table where template_id = 3
  • if template_id is NULL then I need to run a query to look for the page_name in custom_slides table where slide_id = whatever slide id.

I’m not too experienced yet with running multiple queries and UNION and all of that, so if someone could help me get started in creating this query I would really appreciate it.


Table Previews

user_slides

enter image description here

slides

enter image description here

custom_slides

enter image description here

  • 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-28T03:32:24+00:00Added an answer on May 28, 2026 at 3:32 am

    I believe this query should fetch the data you want:

    SELECT slide_id, sort_order, COALESCE(`templates`.page_name, `custom_slides`.page_name)  
    FROM `user_slides` 
    JOIN `slides` ON `slides`.slide_id = `user_slides` .slide_id
    LEFT OUTER JOIN `templates` ON `templates`.template_id = `slides`.template_id
    LEFT OUTER JOIN `custom_slides` ON `slides`.template_id IS NULL AND `custom_slides`.slide_id = `slides`.slide_id
    WHERE `user_slides`.user_id = 1
    

    Clarification:
    This is basically the select query you posted with a few joins.
    First the slides table is joined matching the slide_id.
    Then the templates table is joined, the outer join makes sure the rows where template_id is NULL are still included. And last the custom_slides table is joined but only if template_id is NULL. then using COALESCE we select the page name from either custom_slides or templates.

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

Sidebar

Related Questions

I have a couple of tables which are used to log user activity for
Quick summary: I have a Rails app that is a personal checklist / to-do
--Summary (shortened)-- I have a controller that loads a profile object from the corresponding
Summary: Every field rows of detailsview have 2 td and their first td can
You may have noticed that we now show an edit summary on Community Wiki
I have two tables of concern here: users and race_weeks. User has many race_weeks,
i have two db tables in my codeigniter project. As simplified summary, page page_lang
I have an application that displays league tables for sporting leagues. These tables are
I currently have quite a messy query, which joins data from multiple tables involving
I have an entity model which has some tables added from my DB. I

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.