PrisonPants PrisonPants - 5 months ago 25
MySQL Question

check sql tables

There's a mysql command line it should print

TXT
row when
STATUS
row is
2000
in another table with the same
ID
= 1 , its like connecting to another table;

First table (
tb_users
):

ID | TXT
----------
1 | 9


Second table (
tb_check
):

ID | STATUS
----------
1 | 2000


my mysql command line:

SELECT * FROM `tb_users` ORDER BY RAND() LIMIT 1

Answer

Query should be something like this,

SELECT * 
FROM tb_users TU 
    JOIN tb_check TC ON TU.id=TC.id 
WHERE TC.STATUS=2000;

You've use JOIN in order to get the result from connecting tables. By connecting tables I mean We need to use foreign key.