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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:04:22+00:00 2026-06-03T04:04:22+00:00

So I am working on a game and I would like to make my

  • 0

So I am working on a game and I would like to make my code a bit easier if possible. I have two tables that I need to query from, one table that I want to return the user id from, and the other table to do some background checking.

Stats table:
userid | gold | attack | defense | bonus | …

Logs table:
logid | attacker | attacked | time | …

Here’s the two queries I will probably have:

SELECT userid AS user FROM stats WHERE ($attack + $bonus) > (defense + bonus) ORDER BY gold DESC LIMIT 1

SELECT COUNT(*) AS count FROM logs WHERE attacker = $id AND attacked = user AND date > $time – 86400

the $ variables are php variables of course, and ‘user’ in the second query refers to the “AS user” in the first query. My goal is to return the userid of the person with the highest gold that I can attack, whom I have attacked less than 5 times in the last day.
I’m not quite sure how to join the two, but I would like to if possible!

  • 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-03T04:04:24+00:00Added an answer on June 3, 2026 at 4:04 am

    Try this (not tested):

    SELECT s.userid AS user 
    FROM stats s
    LEFT JOIN logs l ON (l.attacked = s.userid) // attacked is the one I want to get from stats with the highest gold
    WHERE ($attack + $bonus) > (s.defense + s.bonus) 
        AND l.attacker = $id
        AND l.date > $time - 86400
    ORDER BY s.gold DESC LIMIT 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a game engine in C++ and I have methods like setColour
I'm working on a game that uses local area network. Like most of multiplayer
I am working on a game that is coded in C++ and I would
I have a little archer game I'm working on, and previously in my code
I am working on a web application (ASP.NET) game that would consist of a
I am developing a 3d shooter game that I would like to run on
I am working on a little card-swapping world-travel game that I sort of envision
Im currently working on a game that uses multi touch to apply zoom to
Background: I have been working on a platformer game written in C++ for a
I am working on a game that has AI logic, movement, etc and drawing.

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.