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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:37:56+00:00 2026-06-11T16:37:56+00:00

So I have a two quesies that the first one select an array based

  • 0

So I have a two quesies that the first one select an array based on the $_SESSION and then is used in the second select.

My problem is that when I have for example for one use one entrie every thing is ok the table will be like this:

|DATA| USER1|
|DATA| USER2|
|DATA| USER3|

But if I have to entries for the same user I got duplicate like this:

|DATA| USER1| [1]
|DATA| USER1| [2]
|DATA| USER2|
|DATA| USER3|
|DATA| USER1| DUPLICATE of FIRST ENTRY USER ABOVE [1]
|DATA| USER1| DUPLICATE OF SECOND ENTRY USER ABOVE [2]

My code looks like this :

function make_table($user_id){
   first_query with this select `Select U.user_id
                                   from users U, tasks T
                                  where T.assigned_to = U.user_id 
                                    and T.status='Assigned'
                                    and U.parent_id = $_SESSION[userid]`;

  foreach ($query_result_worker as $row){
            $user_id_worker = $row['user_id'];

  //second_query with this select 

    SELECT T.task_id, T.job_server_id, T.TIMESTAMP, TT.task_type_name, T.STATUS,
           UO.username AS customer_name, UO.user_id AS customer_id, T.STATUS, T.quantity,
           T.order_id, U.username, T.priority, T.assigned_time, U.username, O.order_id
     FROM task_type TT, orders O, users UO, task_assignment T
     LEFT JOIN users U
        ON T.assigned_to = U.user_id
     WHERE T.task_type_id = TT.task_type_id
        AND O.order_id = T.order_id
        AND O.user_id = UO.user_id
        AND T.STATUS = 'Assigned'
        AND T.assigned_to = $ROW [user_id]
        AND T.TIMESTAMP <= CURRENT_TIMESTAMP
     ORDER BY T.priority DESC, DATE (T.TIMESTAMP), T.quantity DESC, T.task_id

    foreach ($result as $tablerow) {
    make the printing table stuff

     }
}

So I don’t know why it’s duplicating when I got two entries, any help please?

PS: if I have 3 entries for the same user it will be 6 for the same user, duplicates too.

  • 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-11T16:37:57+00:00Added an answer on June 11, 2026 at 4:37 pm

    Try adding DISTINCT to your first query:

    SELECT DISTINCT U.user_id
    FROM
        users U,
        tasks T
    WHERE
        T.assigned_to = U.user_id
        AND T.status='Assigned'
        AND U.parent_id = $_SESSION[userid];
    

    Also, I would avoid using implicit joins, especially when mixing them with explicit outer joins. It makes the query a bit harder to read, and (IMO) easier to make a mistake. Use the INNER JOIN syntax instead.

    Your second query would look more like this:

    SELECT
        T.task_id,
        T.job_server_id,
        T.TIMESTAMP,
        TT.task_type_name,
        T.STATUS,
        UO.username AS customer_name,
        UO.user_id AS customer_id,
        T.STATUS,
        T.quantity,
        T.order_id,
        U.username,
        T.priority,
        T.assigned_time,
        U.username,
        O.order_id
    FROM
        task_type TT
        INNER JOIN task_assignment T
            ON T.task_type_id = TT.task_type_id
        INNER JOIN orders O
            ON O.order_id = T.order_id
        INNER JOIN users UO
            ON UO.user_id = O.user_id
        LEFT JOIN users U
            ON T.assigned_to = U.user_id
    WHERE
        T.STATUS = 'Assigned'
        AND T.assigned_to = $ROW[user_id]
        AND T.TIMESTAMP <= CURRENT_TIMESTAMP
    ORDER BY
        T.priority DESC,
        DATE(T.TIMESTAMP),
        T.quantity DESC,
        T.task_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two SQL queries, where the first one is: select Activity, SUM(Amount) as
I have the following two SQL statements First one: IF(@User_Id IS NULL) BEGIN SELECT
I have two queries that produce the same columns but different rows. The first
I have the following two queries, I believe that the one that uses the
I have two queries. The first one is.. INSERT INTO balik ( balik_date, balik_time,
I have two queries that I would like to have merged into one. The
I have two SQL queries that I would like to combined into one, if
I have two queries that are basically the same: OLD TRANSACTIONS QUERY SELECT t.payment_method,
I have two queries. The first query: select in_gentime from in_time_temp where cardnumber =
I have two queries here. First one shows listings where a cat link =

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.