Jump to content

[SOLVED] SQL inside an SQL


MadnessRed

Recommended Posts

ok, so how to I go up a level if that makes sence?

 

"SELECT * FROM `{{table}}statpoints` WHERE `stat_type` = '1' AND `stat_code` = '1' AND (SELECT `bana` FROM `{{table}}users` WHERE `id` = `^id`) <> '1' ORDER BY `". $Order ."` DESC LIMIT ". $start .",100;"

 

^id <= Should be the `id` from the main query, not the sub query.

Link to comment
Share on other sites

I have a table of peoples statistics, and I want to show a table with the stats of everyone who is not banned.

 

Actually I think if found a better way of doing it, as I am already calling the user table to get the username, I may as well get the banned data from that and just end the while loop there if they are banned.

Link to comment
Share on other sites

Why can't you JOIN the tables together?  Something like this: *not tested*

 

SELECT * FROM table1 t1 LEFT JOIN table2 t2 ON t1.id=t2.id 
WHERE t1.stat_type = 1 AND t1.stat_code = 1 AND t2.banned = 0 
ORDER BY " . $Order . " DESC LIMIT " . $start . " , 100

 

Link to comment
Share on other sites

 

     

 

 

    *       

 

    *       

               

               

 

                 

      Network Timeout

 

               

 

               

               

 

                 

 

      The server at www.devshed.com is taking too long to respond.

 

               

 

             

 

    *       

               

               

                 

                 

                 

               

             

 

           

 

 

   

 

   

   

 

   

   

 

     

What should you do now?

 

 

     

     

 

 

       

       

 

       

       

 

The requested site did not respond to a connection request and the browser has stopped waiting for a reply.

 

    * Could the server be experiencing high demand or a temporary outage?  Try again later.

    * Are you unable to browse other sites? Check the computer's network connection.

    * Is your computer or network protected by a firewall or proxy?  Incorrect settings can interfere with Web browsing.

    * Still having trouble? Consult your network administrator or Internet provider for assistance.

Link to comment
Share on other sites

so what I want is

 

"SELECT * 
FROM {{table}}statpoints LEFT JOIN {{table}}users ON {{table}}statpoints.id = {{table}}users.id 
WHERE `{{table}}statpoints.stat_type` = '1' AND `{{table}}statpoints.stat_code` = '1' AND `{{table}}users.bana` <> '1' ORDER BY `{{table}}statpoints.". $Order ."` DESC LIMIT ". $start .",100;"

 

however when I try that I get

 

Unknown column 'evo1_statpoints.stat_type' in 'where clause'<br />SELECT *

FROM evo1_statpoints LEFT JOIN evo1_users ON evo1_statpoints.id = evo1_users.id

WHERE `evo1_statpoints.stat_type` = '1' AND `evo1_statpoints.stat_code` = '1' AND `evo1_users.bana` <> '1' ORDER BY `evo1_statpoints.total_points` DESC LIMIT 0,100;<br />

 

edit: found the bug in that it was the "evo1_statpoints."

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.