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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:02:49+00:00 2026-05-28T15:02:49+00:00

How could i join this multi query with just a single mysql query ?

  • 0

How could i join this multi query with just a single mysql query ?

$query = $mysql->query("select rate from postages where city=$city");

if($query->num_rows == 0)
{
    $query = $mysql->query("select rate from postages where subdistrict=$subdistrict");

    if($query->num_rows == 0)
    {
        $query = $mysql->query("select rate from postages where district=$district");           
    }
}

Thanks for your help.

  • 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-28T15:02:51+00:00Added an answer on May 28, 2026 at 3:02 pm

    If you wanted to get the exact same result as you have in your example you could do:

    SELECT IFNULL(c.rate, IFNULL(d.rate, s.rate)) as rate FROM (
        (SELECT rate, count(*) FROM postages where city = '$city') as c,
        (SELECT rate, count(*) FROM postages where district = '$district') as d,
        (SELECT rate, count(*) FROM postages where subdistrict = '$subdistrict') as s
    )
    

    You could also do it another way… Which only runs the district query if where is the city query returns 0 rows, and only runs the subdistrict call if the district query returns 0 rows:

    SELECT IFNULL(
            (SELECT rate FROM postages where city = '$city'),
         IFNULL(
           (SELECT rate FROM postages where district = '$district' limit 1),
           (SELECT rate FROM postages where subdistrict = '$subdistrict' limit 1)
         )
    ) as rate
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query which involves a table from another server: select count(serialno), max(convert(varchar(10),Crtd_DateTime,101))
I am trying an inner join like this. select R.ReservationID, R.BookingNumber,P.FirstName, P.LastName from Reservation
I have two query like this; SELECT j.ID, j.Pkey, j.SUMMARY, j.CREATED, j.RESOLUTIONDATE ,j2.SUMMARY, j2.CREATED,
I have this simple SQL statement: select Expr1.value - Expr2.value FROM (SELECT Expr1 =
Are there any good professional associations for IT Managers that I could join and
Could somebody please name a few. I could given time, but this is for
I am trying to inner join 2 temp tables I know this can be
I have this query that works fine. It selects rows into the SY.UserOptions table
Hi i keep getting the error The multi-part identifier Users.USERS_ID could not be bound
I've got a query that presently looks something like this (I'll simplify it to

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.