I need to write a query which must include use of INNER JOIN, but did not manage to write it correctly.
In PhpMyAdmin, I created a database with two related tables of users:
Table #1 is called “Usertype” and has two columns:
1.typnum (auto increment)
2.typdsc – which has three types of values: Inactive, Guest and Webmaster
Table #2 is called “Users” and has five columns:
- usrnum
- usrlogin
- usrpassword
- usrrealname
- usrtyp (the foreign key I connected with typnum)
What I need to show is the following records of Guests and Webmasters: usrlogin, usrpassword, usrrealname and the name of their types (while using Inner Join for the last one).
In other words, I need to show records which are NOT ‘Inactive’, show what their types are instead and the rest of their values EXCEPT usrnum
This is the query I tried to write for this:
SELECT users.usrlogin,users.usrpassword,users.usrrealname AND user.usrtyp
FROM users
WHERE usrtyp NOT IN 'Inavctive' AND INNER JOIN userstypes ON users.usrtyp = userstypes.typnum
Thank you in advance!
2
Answers
Try this:
order matters in sql where is last. Also remove the random AND