two mysql tables
#1

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.
Reply
#2

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.
Reply
#3

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

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)