Found 10476 Articles for Python

How can you perform full join on two tables using MySQL in Python?

Pawandeep Kaur
Updated on 10-Jun-2021 12:53:59

290 Views

We can join two tables in SQL based on a common column between them or based on some specified condition. There are different types of JOIN available to join two SQL tables.Here, we will discuss about the FULL join on two tables. In the FULL JOIN, all the records from both the tables are included in the result. For the records for which no matching is found, NULL is inserted on the either sides.SyntaxSELECT column1, column2... FROM table_1 FULL JOIN table_2 ON condition;Let there be two tables, “Students” and “Department” as folllows −Students+----------+--------------+-----------+ |    id    | Student_name | ... Read More

How can you perform right join on two tables using MySQL in Python?

Pawandeep Kaur
Updated on 10-Jun-2021 12:51:42

251 Views

We can join two tables in SQL based on a common column between them or based on some specified condition. There are different types of JOIN available to join two SQL tables.Here, we will discuss about the RIGHT join on two tables.In the RIGHT JOIN, all the records from the second table or the right table are always included in the result. From the left table, the matching records are joined to the records of the right table. If there is no matching record found for a row in right table, then None is joined with that record.The tables are ... Read More

How can you perform left join on two tables using MySQL in Python?

Pawandeep Kaur
Updated on 10-Jun-2021 12:49:45

672 Views

We can join two tables in SQL based on a common column between them or based on some specified condition. There are different types of JOIN available to join two SQL tables.Here, we will discuss about the LEFT join on two tables. The tables can be joined using the LEFT join. In the LEFT JOIN, all the records from the first table or the left table are always included in the result. From the right table, the matching records are joined to the records of the left table. If there is no matching record found for a row in left ... Read More

How can you perform inner join on two tables using MySQL in Python?

Pawandeep Kaur
Updated on 10-Jun-2021 12:49:08

3K+ Views

We can join two tables in SQL based on a common column between them or based on some specified condition. There are different types of JOIN available to join two SQL tables.Here, we will discuss about the inner join on two tables.JOIN and INNER JOIN both work the same way. The INNER JOIN matches each row in one table with every row in other table and allows to combine the rows from both the tables which either have somecommon column or which satisfy some condition which is specified.When applying join among two tables, we need to specify the condition based ... Read More

How can you avoid getting an error if you are deleting a table which does not exist using Python?

Pawandeep Kaur
Updated on 10-Jun-2021 12:46:49

648 Views

There might be a scenario where you might be deleting a table which actually does not exist in your database. It is possible that while executing the command to delete a table from the database, we may give wrong name of the table which doesnot exist in our database. The another possibility is that you are deleting a table which was already deleted by someone else who has access to the database. In this scenario you will get an error while executing the command since the table you wish to delete is not present.This error can be avoided by checking ... Read More

Explain the use of SELECT DISTINCT statement in MySQL using Python?

Pawandeep Kaur
Updated on 10-Jun-2021 12:37:56

1K+ Views

Inside SQL tables, columns usually contain duplicate values. We may sometimes need to get only the distinct or different values present in a column in our table since the duplicate values makes it difficult for us to analyze the results returned by the query.Example:Suppose, we have a table named Customers which conatins details about our customers, their names, age and country etc. We need to know to which different countries do our customers belong. We may have 10 customers from India, 15 from America and so on. If we simply select the country column, this will return us the whole ... Read More

How can you delete a table from a database in MySQL Python?

Pawandeep Kaur
Updated on 10-Jun-2021 12:38:16

249 Views

It can be at times required to delete the whole table from the database. It is bad use of the storage to keep the unwanted data in the database. Suppose, we have a table named “Employees” in our database and due to some reasons , we do not require this table in our database anymore. Therefore, it is best to delete the particular table which is of no use to us.This is done using the “DROP TABLE” command. This table deletes the entire table from the database.SyntaxDROP TABLE table_nameHere, table_name specifies the name of the table you want to delete.Steps ... Read More

How can you update certain values in a table in MySQL using Python?

Pawandeep Kaur
Updated on 10-Jun-2021 12:38:34

1K+ Views

The data in the table may be outdated and we may require to change the data after some time. Suppose, we have a table of Students and one of the students have changed their address. We require to change the address of the student in the database to avoid any problems in future due to wrong data.The “UPDATE” statement in MySQL is used to update some value in the table.The SET clause is used to set the new value in the column. The WHERE clause is used to identify where in the table do we need to update the data ... Read More

How can you retrieve a particular number of records from a table starting from some specified row number in Python MySQL?

Pawandeep Kaur
Updated on 10-Jun-2021 12:38:52

1K+ Views

Most frequently, we do not require to select all the rows from the table. We may at times need to retrieve a particular number of records from a table, starting from some specific index. Suppose, we have a table of 10 records. We need to select 5 rows from the table starting from 3rd row.This is done using the LIMIT and OFFSET clause along with the SELECT statement. The LIMIT is used to specify the number of rows that you want to retrieve. The OFFSET is used to specify the starting position from where the rows are to be fetched. ... Read More

How can you delete a record from a table using MySQL in Python?

Pawandeep Kaur
Updated on 10-Jun-2021 12:37:21

448 Views

We may at times need to delete certain rows from a table. Suppose, we have a table of details of students in the class. It is possible that one of the students left the class and hence, we do not require the details of that particular student. Hence, we need to delete that particular row or record from the table.The “DELETE FROM” statement in MySQL is used to delete a row or record from the table, The “WHERE” clause is used to specify the row to be deleted. If WHERE clause is not used, then all the records will be ... Read More

Advertisements