Python

Python MongoDB Create Database

Creating a Database To create a database in MongoDB, start by creating a MongoClient object, then specify a connection URL with the correct ip address and the name of the database you want to create. MongoDB will create the database…

Python MongoDB

Python can be used in database applications. One of the most popular NoSQL database is MongoDB. MongoDB MongoDB stores data in JSON-like documents, which makes the database very flexible and scalable. To be able to experiment with the code examples…

Python MySQL Join

Join Two or More Tables You can combine rows from two or more tables, based on a related column between them, by using a JOIN statement. Consider you have a “users” table and a “products” table: users { id: 1,…

Python MySQL Limit

Limit the Result You can limit the number of records returned from the query, by using the “LIMIT” statement: Example Select the 5 first records in the “customers” table: import mysql.connector mydb = mysql.connector.connect(   host=”localhost”,   user=”yourusername”,   password=”yourpassword”,…

Python MySQL Update Table

Update Table You can update existing records in a table by using the “UPDATE” statement: Example Overwrite the address column from “Valley 345” to “Canyon 123”: import mysql.connector mydb = mysql.connector.connect(   host=”localhost”,   user=”yourusername”,   password=”yourpassword”,   database=”mydatabase” )…

Python MySQL Drop Table

Delete a Table You can delete an existing table by using the “DROP TABLE” statement: Example Delete the table “customers”: import mysql.connector mydb = mysql.connector.connect(   host=”localhost”,   user=”yourusername”,   password=”yourpassword”,   database=”mydatabase” ) mycursor = mydb.cursor() sql = “DROP…

Python MySQL Delete From By

Delete Record You can delete records from an existing table by using the “DELETE FROM” statement: Example Delete any record where the address is “Mountain 21”: import mysql.connector mydb = mysql.connector.connect(   host=”localhost”,   user=”yourusername”,   password=”yourpassword”,   database=”mydatabase” )…

Python MySQL Order By

Sort the Result Use the ORDER BY statement to sort the result in ascending or descending order. The ORDER BY keyword sorts the result ascending by default. To sort the result in descending order, use the DESC keyword. Example Sort…

Python MySQL Where

Select With a Filter When selecting records from a table, you can filter the selection by using the “WHERE” statement: Example Select record(s) where the address is “Park Lane 38”: result: import mysql.connector mydb = mysql.connector.connect(   host=”localhost”,   user=”yourusername”,…