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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:19:19+00:00 2026-06-12T17:19:19+00:00

Tables: helps (important are id and fecha fields) shared helps (helps referenced by other

  • 0

Tables:

helps (important are id and fecha fields)

enter image description here

shared helps (helps referenced by other users with a different date)

enter image description here

So,

All helps from a user (user_id = 1)

SELECT * FROM helps WHERE id_user = 1

All helps from user and the ones he refferenced

SELECT * FROM helps where id_user = 1 or id IN (SELECT helpid FROM shared_helps WHERE userid = 1)

I know you guys will find it a very ugly query (I hoped you could show me the light) but it seems to show the results I want. Problem is that this way shared_helps.fecha is ignored so it makes no effect in the ORDER BY, how can I achieve this?

  • 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-12T17:19:21+00:00Added an answer on June 12, 2026 at 5:19 pm
    SELECT
      helps.*
    FROM
      helps
    LEFT JOIN
      shared_helps
        ON  shared_helps.helpid = helps.id
        AND shared_helps.userid = 1
    WHERE
         helps.id_user = 1
      OR shared_helps.userid = 1
    ORDER BY
      CASE WHEN helps.id_user = 1 THEN 0 ELSE 1 END,
      shared_helps.fecha
    

    EDIT

    Based on your comment, try this…

    ORDER BY
      COALESCE(shared_helps.fecha, helps.fecha)
    

    Or possibly this…

    ORDER BY
      helps.fecha
    

    I’m honestly not 100% certain what you need. Perhaps you could include some sample data and the output you desire for that sampel data?

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

Sidebar

Related Questions

I have a Database with the tables Users and Uploads . The important columns
I am using this function to list items from table helps depending on parameters:
I need help regarding JOIN tables to get category name & author name from
Help from the SQL Gods Required Table 1 - DistinctQuotes This tables holds information
hope someone can help. I have two tables: Users -UserID -UserName UsersType -UserTypeID -UserID
Who can help me make the following query work... Both tables have the fields
Here's the situation. I have two tables: users (registered users of the website), messages
I have a main JFrame that is interactive, i.e. user sets different options. After
UPDATE Finally managed to work it out! Thanks for all the help from everyone.
I am using Mysql and have these tables: (only important columns shown) Person id

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.