Found 26504 Articles for Server Side Programming

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

244 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

445 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

How can you select data from a table based on some criteria using MySQL in Python?

Pawandeep Kaur
Updated on 10-Jun-2021 12:18:26

759 Views

It is not frequently required to select all the data from the table. Instead , we need to select data or rows from the table based on some condition or criteria.Suppose, we have a table which includes names and marks of many students. Now, we need to get names of the students whose marks are above 90. This basically requires us to select data based on some criteria ,which is(marks>=90).Therefore, we are provided with “WHERE” statement in MySQL which allows us to select data from the table based on some specified criteria.SyntaxSELECT * FROM table_name WHERE conditionHere, table_name specifies the ... Read More

What is the fetchone() method? Explain its use in MySQL Python?

Pawandeep Kaur
Updated on 10-Jun-2021 12:12:58

9K+ Views

Fetchone() methodFetchone() method is used when you want to select only the first row from the table. This method only returns the first row from the MySQL table.Use of fetchone() methodThe fetchone() is not used as a query to be used to the cursor object. The query passed is “SELECT *” which fetches all the rows from the table.Later , we operate fetchone() method on the result returned by “SELECT *”. The fetchone() method then fetches the first row from that result.Steps you need to follow to fetch first row from a table using MySQL in pythonimport MySQL connectorestablish connection ... Read More

How to select all the data from a table using MySQL in Python?

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

3K+ Views

The tables in MySQL consist of rows and columns. The columns specify the fields and the rows specify the records of data. The data in the tables needs to be fetched to use. We may at times need to fetch all the data from the MySQL table.All the rows can be fetched from the table using the SELECT * statement.SyntaxSELECT * FROM table_nameThe * in the above syntax means to fetch all the rows from the table.Steps you need to follow to select all the data from a table using MySQL in pythonimport MySQL connectorestablish connection with the connector using ... Read More

How to install NumPy for Python 3.3.5 on Mac OSX 10.9?

Vikram Chiluka
Updated on 22-Sep-2022 13:03:44

1K+ Views

This article will show you how to install Numpy in Python on MacOS using 3 different methods as below. Using Homebrew Using Anaconda Using pip What is Numpy NumPy is gaining popularity and being used in various commercial systems. As a result, it's critical to understand what this library has to offer. NumPy is a powerful Python library due to its syntax, which is compact, powerful, and expressive all at the same time. It allows users to manage data in vectors, matrices, and higher-dimensional arrays, and it is also used in array computing in the industry. Method 1: ... Read More

Program to find out the lowest common ancestor of a binary tree of given nodes using Python

Arnab Chakraborty
Updated on 29-May-2021 13:15:40

182 Views

Suppose, we are given a binary tree and are asked to find out the lowest common ancestor of all the nodes in the tree. The lowest common ancestor in a binary tree is the lowest node of which the nodes x1, x2, x3, ...., xn are descendants. A particular node can also be a descendant of itself. We have to find the node and return it as an output. The inputs are the root node of the tree and the list of nodes that we have to find the ancestor of.So, if the input is likeand the list of nodes ... Read More

Advertisements