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

  • Home
  • SEARCH
  • 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 6914833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:23:54+00:00 2026-05-27T09:23:54+00:00

I have this query: SELECT DISTINCT 1 as table_id, users.id, users.username, a.titles_name title1, b.titles_name

  • 0

I have this query:

        SELECT DISTINCT 1 as table_id, users.id, users.username, a.titles_name title1, b.titles_name as title2, contacts.accepted
        FROM users
        LEFT JOIN contacts ON users.id = contacts.contact_id
        LEFT JOIN titles as a ON a.id = users.title_1
        LEFT JOIN titles as b ON b.id = users.title_2
        WHERE contacts.request_id = ' + $this->session->userdata('user_id') . '
        UNION DISTINCT
        SELECT DISTINCT 2 as table_id, users.id, users.username, a.titles_name title1, b.titles_name as title2, contacts.accepted
        FROM users
        LEFT JOIN contacts ON users.id = contacts.request_id
        LEFT JOIN titles as a ON a.id = users.title_1
        LEFT JOIN titles as b ON b.id = users.title_2
        WHERE contact_id = ' . $this->session->userdata('user_id')

Would it be possible to do something similar in mongodb?

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

    Lets break down the components of the query:

    SELECT DISTINCT 1 as table_id, users.id, users.username, a.titles_name title1, b.titles_name as title2, contacts.accepted
    FROM users
    

    Yes, this is just a distinct query asking for a subset of fields. Mongo does that.

    LEFT JOIN contacts ON users.id = contacts.contact_id
    LEFT JOIN titles as a ON a.id = users.title_1
    LEFT JOIN titles as b ON b.id = users.title_2
    WHERE contacts.request_id = ' + $this->session->userdata('user_id') . '
    

    This is a join, which you cannot do in mongo. However, you can de-normalize so it becomes unnecessary or do similar joining of data on the client side.

    UNION DISTINCT
    SELECT DISTINCT 2 as table_id, users.id, users.username, a.titles_name title1, b.titles_name as title2, contacts.accepted
    FROM users
    LEFT JOIN contacts ON users.id = contacts.request_id
    LEFT JOIN titles as a ON a.id = users.title_1
    LEFT JOIN titles as b ON b.id = users.title_2
    WHERE contact_id = ' . $this->session->userdata('user_id')
    

    This is a union, which you could do on the client side and for which the query contains the same components i’ve described above.

    TLDNR: No, you can’t do this exact query in mongodb, but you can achieve the same result.

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

Sidebar

Related Questions

I have this query: SELECT DISTINCT IM.EDIFICIOS_ID, TI.TITULAR FROM IMPORTACION IM INNER JOIN I_EDIFICIO
I have this query... SELECT Distinct([TargetAttributeID]) FROM (SELECT distinct att1.intAttributeID as [TargetAttributeID] FROM AST_tblAttributes
I have a mysql query like this: $topicreplycount = mysql_query('SELECT COUNT(DISTINCT post_msg_id) FROM phpbb_attachments
I have this query which takes 27 seconds to execute: SELECT ocal_files.*, count(DISTINCT ocal_favs.username)
I have this SQL query: SELECT DISTINCT tb.SERIAL_NUM, tb.REVISION_NUM, tb.JOB_NUM, tb.JOB_TOTAL, tb.TEST_PROC, tb.BOX_NUM, tb.TEST_BENCH,
I have managed to bring the following output with this query SELECT DISTINCT IF(purchaseproduct_customerid=0,contactperson,vendorname)
This is a simpler version of the query I have. Alias1 as (select distinct
I have this query: SELECT * From checkfinale where AssociateID = 51 AND `CompletedDate`
I have this query , take long time when I executed it SELECT DISTINCT
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt

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.