SA-MP Forums Archive
two mysql tables - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: two mysql tables (/showthread.php?tid=501317)



two mysql tables - audriuxxx - 17.03.2014

Hi,

I have two tables:

Код:
players
and

Код:
players1
And i want to get players which have the most XP, but i want to order that from both tables, how to make that querie?

Because if i do for ex for players table

Код:
SELECT XP FROM players ORDER BY XP DESC LIMIT 10
I tried

Код:
SELECT XP FROM players,players1 ORDER BY XP DESC LIMIT 10
But this don't work.


Re: two mysql tables - Thomaske - 17.03.2014

Try something like this:

PHP код:
select `YourDBName`.`players`.`username` AS `username`,`YourDBName`.`players`.`xp` AS `xpfrom `YourDBName`.`players
union 
select 
`YourDBName`.`players1`.`username` AS `username`,`YourDBName`.`players1`.`xp` AS `xpfrom `YourDBName`.`players1
order by `xpdesc 
the best was if to create a view in your database of a table and use this query, then it is always logged in the view.

the query is ceated to put the highest score on top.

if this helped you +rep.

if you need more information let me know.


Re: two mysql tables - VishvaJeet - 18.03.2014

Use this Dude:
Код:
SELECT * FROM players ORDER BY XP DESC LIMIT 0,10



Re: two mysql tables - CuervO - 18.03.2014

You need to use the SQL join statement joining on a common field.

Код:
SELECT players.XP, players1.XP
FROM players
JOIN players1 ON players.ID = players1.ID
ORDER BY XP DESC
LIMIT 10
That will basically return the data from two tables where for example, the ID from the first is equal to the ID of the second. ****** for more information.