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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:24:38+00:00 2026-05-24T09:24:38+00:00

I want to combine the following queries into a single query: SELECT val FROM

  • 0

I want to combine the following queries into a single query:

SELECT val FROM resource WHERE facet="all" and urlId="1234"
SELECT val FROM resource WHERE facet="your" and urlId="1234"
SELECT val FROM resource WHERE facet="base" and urlId="1234"

Oh — there are multiple “facets” for each urlId. But only one row per “facet”. This table was setup by somebody else. We are migrating away. Obviously it would be better to have a column for each “facet” and a single row, but it’s too late for that.

I can do this with multiple queries, but would like to have a faster/better solution.

<pre>
mysql> describe resource;
+-------------+-------------------------------------+------+-----+-------------------+-----------------------------+
| Field       | Type                                | Null | Key | Default           | Extra                       |
+-------------+-------------------------------------+------+-----+-------------------+-----------------------------+
| resId       | int(11) unsigned                    | NO   | PRI | NULL              | auto_increment              |
| urlId       | int(11)                             | NO   | MUL | NULL              |                             |
| sectionId   | int(3)                              | YES  |     | NULL              |                             |
| mode        | enum('archive','live','edit','dev') | NO   |     | edit              |                             |
| facet       | varchar(50)                         | NO   | MUL | NULL              |                             |
| typeId      | int(1)                              | NO   |     | 1                 |                             |
| val         | mediumtext                          | NO   |     | NULL              |                             |
| itemOrder   | tinyint(2)                          | NO   |     | 1                 |                             |
| editorId    | varchar(30)                         | NO   |     | NULL              |                             |
| created     | datetime                            | NO   |     | NULL              |                             |
| lastUpdated | timestamp                           | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+-------------+-------------------------------------+------+-----+-------------------+-----------------------------+
11 rows in set (0.05 sec)
</pre>

Remember: in soviet russia, SQL queries you.

  • 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-24T09:24:39+00:00Added an answer on May 24, 2026 at 9:24 am

    This is my preferred method which will use your indexes:

    SELECT resource.val FROM
      ( (SELECT "all" AS name) UNION (SELECT "your") UNION (SELECT "base") ) AS facets
      LEFT JOIN resource ON( resource.facet  = facets.name AND resource.urlId = "1234" )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following queries: Query 1: Select * from T10,T11,T12,T13,T14 where T10.C0 =
I want to combine the following two statements: select password from sys.user$ where name='SYSMAN';
I want to combine these two queries into one: mysql_query(INSERT INTO categories (name, parent)
I have the following query: SELECT title, karma, DATE(date_uploaded) as d FROM image ORDER
I have the following code and I want to combine phase space plots into
I'm trying to combine the following expressions into a single expression: item => item.sub,
I try to combine result from several queries and put them into an array.
I have the following query: SELECT COUNT(package) as advanced_count FROM users WHERE package =
I want to combine the two following queries, can anyone give me a idea
I want to combine AND OR mysql queries in CI. I have already seen

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.