How to get information that is in 2 tables mysql [duplicate]

-1

Table 01: $file

Table 02: $users

I want to do so, when a user for level ID = 30 displays a msg

EXAMPLE, FILE 01 ( $file->userid = 20 that is, this user id is in table 02, $users->id )

TABLE $ FILE

TABLE$USERS

  

Imean..Itwouldlooklikethis:$file->userId$users->id->levelId??

if (QUANDO ESSE ARQUIVO FOR DE UM USER LEVEL 30) {
	echo "teste";
}
    
asked by anonymous 31.07.2018 / 00:53

1 answer

1

Use the JOIN clause of SQL:

SELECT * FROM users as u
INNER JOIN file as f ON u.id = f.userId
WHERE u.level_id = 30

Explaining, line:

  • Select everything from table users

  • Joins with table file where ids of each table are equal

  • Adds a condition to return only those with a level equal to 30

  • 31.07.2018 / 01:29