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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:50:52+00:00 2026-06-18T10:50:52+00:00

I have a table that has records id_queue | user_id | id_book | status

  • 0

I have a table that has records

id_queue | user_id | id_book | status
   69    |    5    |    4    |   1
   133   |    3    |    4    |   2
   142   |    1    |    4    |   0

I want a query that will give me this result

id_queue | id_queue
   69    |    142    
   133   |    null 

I’ve tried something like this

SELECT s1.`id_queue`,s2.`id_queue` FROM `second` as s1
LEFT JOIN `second` as s2 ON s2.`book_id`=4 AND s2.`status` IN (0)
WHERE s1.`book_id`=4 AND s1.`status` IN (1,2,4) 

but it keeps bringing me this result.

id_queue | id_queue
   69    |    142    
   133   |    142

I think this is because I don’t have anything identical for conditions. What can I do?

  • 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-18T10:50:53+00:00Added an answer on June 18, 2026 at 10:50 am

    The issue is that you are joining on the book_id not the status, so you will always have a matching row.

    If you want to hide the second instance of the second id_queue then you can use user defined variables:

    select Queue1,
      case when seq = 1 then queue2 else null end Queue2
    from
    (
      select 
        Queue1,
        Queue2,
        @row:=(case when @prev=Queue2 then @row else 0 end) +1 as Seq,
        @prev:=Queue2 
      from
      (
        SELECT 
          s1.`id_queue` Queue1,
          s2.`id_queue` Queue2
        FROM `second` as s1
        LEFT JOIN `second` as s2 
          ON s1.`id_book` = s2.`id_book`
          AND s2.`status` = 0
        WHERE s1.`id_book`=4 
          AND s1.`status` IN (1,2,4)
      ) src, (SELECT @row:=0, @prev:=null) r
      order by Queue1, Queue2
    ) s1
    order by Queue1, Queue2
    

    See SQL Fiddle with Demo

    The result is:

    | QUEUE1 | QUEUE2 |
    -------------------
    |     69 |    142 |
    |    133 | (null) |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that will have 500,000+ records. Each record has a LineNumber
I have a table that has records with a structure similar to this.. ID
I have one table that has sales records and another table that has additional
I have a table that has millions of records and we are looking at
I have a table within my database that has many records, some records share
Here is the scenario: I have a table that records the user_id, the module_id,
I have a query ( original question that has table structure too ) that
I have a table of reports that has these relevant fields: user_id (int 11)
I have a table which has records that contain a persons information and a
I have a mongo table that has statistical data like the following.... course_id status

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.