In what way joins are useful and how many types of joins are there?

Submitted 5 months, 3 weeks ago
Ticket #377
Views 89
Language MYSQL
Priority Medium
Status Closed

I am little bit confused about joins in MYSQL?

In what way we can use them?

And how many types are there?

Any help wil be greatly useful........

Submitted on Apr 03, 21
add a comment

1 Answer

Verified

Joins are used when you need data from multiple tables at the same time. Please note that there must be a foreign key (FK) defined.
You can use as many tables as you need, but I'll give you a simple example with only 2 tables.

Let's say you have 2 tables: users and user_info.

In the users table you have: id, username and password

In the user_info table you have: id, name, age, email, address, phone, and user_id (FK)

If for a logged in user you want to display his info (let's say an account page), you'll need to use join.

For example:

SELECT ui.name, ui.age, ui.email 
FROM user_info AS ui
JOIN users as u
ON u.id = ui.user_id
WHERE u.id=1

Some references:

1. Validate SQL query:  (https://www.eversql.com/sql-syntax-check-validator/)
2. SQL Join Types: (https://www.w3schools.com/sql/sql_join.asp)

Submitted 5 months, 2 weeks ago


Wanna Post Ad?
Reach a large group of audience by posting an ad about your business here. For more details
Drop us a Message