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

The Archive Base Latest Questions

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

MySQL (simplified tables) table_1 +—-+——-+ | id | title | +—-+——-+ | 1 |

  • 0

MySQL (simplified tables)

table_1

+----+-------+
| id | title |
+----+-------+
| 1  | test  |
+----+-------+
| 2  | test  |
+----+-------+
| 3  | test  |
+----+-------+

table_2

+----+
| id |
+----+
| 1  |
+----+

table_3

+----+
| id |
+----+
| 1  |
+----+
| 3  |
+----+

PHP

$a = mysql_query("SELECT t1.id FROM table_1 AS t1 WHERE MATCH(t1.title) AGAINST ('test' IN BOOLEAN MODE)");

What I want to do now is:

a) If the id is included in table_2 OR table_3 it should be ranked higher than if it’s only present in table_1

b) If the id is included in table_2 AND table_3 it should be ranked even higher

So, the output should be:

1, 3, 2
  • 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-23T00:54:40+00:00Added an answer on May 23, 2026 at 12:54 am
    select table_1.id, 
      (case
      when max(table_2.id) is not null AND max(table_3.id) is not null then 0
      when max(table_2.id) is not null OR max(table_3.id) is not null then 1
      else 2
      end) rank
    from table_1 left outer join table_2 on
       table_1.id = table_2.id left outer join table_3 on
       table_1.id = table_3.id
    group by table_1.id
    order by rank
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL database with two tables (simplified for this question): movies table
Can I match and replace a text pattern in a MYSQL select? EDIT For
I have two associated tables (simplified schema) mysql> describe booking; +----------------+------------+ | Field |
I have the following (simplified) result from SELECT * FROM table ORDER BY tick,refid
I have a MySQL table with the following data (simplified): INSERT INTO `stores` (`storeId`,
I've got a table of student information in MySQL that looks like this (simplified):
Below is my (simplified) schema (in MySQL ver. 5.0.51b) and my strategy for updating
I'm using a MySQL database to store scores for my game. A very simplified
How does one handle ties when ranking results in a mysql query? I've simplified
MySQL ResultSets are by default retrieved completely from the server before any work can

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.