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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:13:57+00:00 2026-06-12T14:13:57+00:00

This are the tables that are used in the querys: HELPS (Fields relevant: id,

  • 0

This are the tables that are used in the querys:

HELPS (Fields relevant: id, id_user)

enter image description here

FRIENDS

enter image description here

SHARED_HELPS

enter image description here

So:

This query (works) returns al the helps from a user and all from other users that he referenced:

$sql = 'SELECT
                      helps.*,CASE WHEN shared_helps.userid IS NULL THEN 0 ELSE shared_helps.userid END as is_shared, CASE WHEN shared_helps.userid IS NULL THEN helps.fecha ELSE shared_helps.fecha END as ffecha
                    FROM
                      helps
                    LEFT JOIN  shared_helps
                        ON  shared_helps.helpid = helps.id
                        AND shared_helps.userid = '.$value.'

                    WHERE     (helps.id_user = '.$value.' AND helps.id_group <= 0)  OR shared_helps.userid = '.$value.'



                   ORDER BY ffecha DESC';

Also, this query (works) lists all the helps from a user an the ones from his friends

$sql = 'SELECT  id, title, content, id_user, id_group, id_type, id_loc, avatar, attached, fecha, likes, lan, needsCount, recivedCount
                    FROM
                        (
                            SELECT *, 1 as OrderBy           
                                FROM helps 
                             WHERE id_user = '.$value.' or id_user IN (SELECT helpid FROM shared_helps WHERE userid = '.$value.')
                            UNION
                            SELECT  h.*, 2 as OrderBy        
                                 FROM    (
                                        SELECT  id  AS friendsId,
                                                CASE followerid 
                                                    WHEN '.$value.' THEN followingid 
                                                    ELSE followerid 
                                                END AS friend_id
                                        FROM    friends
                                        WHERE   acepted = 1 AND 
                                                (followerid  ='.$value.' OR followingid = '.$value.')
                                    ) AS f
                                        INNER JOIN helps AS h 
                                            ON h.id_user = f.friend_id where id_group < 0
                        ) x
                    ORDER BY ID DESC
                    ';

The thing is to the last one, i need to add the ones that are from other users but he referenced (is like a mix of the two query I posted..)

I tried this:

$sql = 'SELECT  id, title, content, id_user, id_group, id_type, id_loc, avatar, attached, fecha, likes, lan, needsCount, recivedCount,
                            CASE WHEN shared_helps.userid IS NULL THEN helps.fecha ELSE shared_helps.fecha END as ffecha
                    FROM
                        (
                            SELECT *, 1 as OrderBy           
                                FROM helps 
                             WHERE id_user = '.$value.' or id_user IN (SELECT helpid FROM shared_helps WHERE userid = '.$value.')
                            UNION
                            SELECT  h.*, 2 as OrderBy        
                                 FROM    (
                                        SELECT  id  AS friendsId,
                                                CASE followerid 
                                                    WHEN '.$value.' THEN followingid 
                                                    ELSE followerid 
                                                END AS friend_id
                                        FROM    friends
                                        WHERE   acepted = 1 AND 
                                                (followerid  ='.$value.' OR followingid = '.$value.')
                                    ) AS f
                                        INNER JOIN helps AS h 
                                            ON h.id_user = f.friend_id where id_group < 0
                        ) x
                    LEFT JOIN  shared_helps
                            ON  shared_helps.helpid = x.id
                            AND shared_helps.userid = '.$value.'

                        WHERE     (x.id_user = '.$value.' AND helps.id_group <= 0)  OR shared_helps.userid = '.$value.'



                    ORDER BY ffecha DESC
                    ';

But i got:

Column 'id' in field list is ambiguous

But this is obviously out of my knowledge.. Can anyone show me the ligth?

  • 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-12T14:13:59+00:00Added an answer on June 12, 2026 at 2:13 pm

    if I’m not mistaken, you need to specify where column ID does it come from because all tables has column ID.

    Try adding the tableName Helps and since it contains in a subquery x

    SO in your query,

    SELECT x.ID, ....
    FROM...
    WHERE ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this SQL Query that pulls data from 3 tables. I am unable
I got this error running a query that goes against 2 tables with combined
I used the Vertical Table Header Cell Renderer that is available in this site
I have a 3 tables that look like this: (source: InsomniacGeek.com ) On the
I've got 3 tables that are something like this (simplified here ofc): users user_id
Let's say I have two tables that look like this: TH TH TH TH
I'm working on a project that contains 5 tables: This-->ThisThat<--That-->ThatFoo<--Foo I've defined the table
I have a number of static classes that contain tables like this: using System;
I know that horizontal partitioning...you can create many tables. How can you do this
Lets say that I have three tables, customers, orders and orderDetails. I'm doing this:

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.