Learn Programming in Python with Cody Jackson by Cody Jackson
Author:Cody Jackson
Language: eng
Format: epub
Tags: COM051300 - COMPUTERS / Programming / Algorithms, COM051360 - COMPUTERS / Programming Languages / Python, COM051440 - COMPUTERS / Software Development and Engineering / Tools
Publisher: Packt Publishing
Published: 2018-11-29T07:11:54+00:00
Using SQL to query a database
To query a table using SQL, you simply tell the database what it is you're trying to do. If you want to get a list of the customers or a list of orders in the system, just select what parts of the table you want to get.
Note that the following code snippets are not Python-specific. Additionally, SQL statements are not case-sensitive but are usually written in uppercase for clarity, so you know what words are SQL-related.
Returning data with SQL is shown in following snippet:
SELECT * FROM Customers
The command simply pulls everything from Customers_table and prints it. The printed results may be textual or have grid lines, depending on the environment you are using, but the information will all be there.
You can also limit the selection to specific fields, such as following example:
SELECT Last_name, First_name FROM Customers
SELECT Address FROM Customers WHERE State == "NY"
The second SQL query uses the WHERE statement, which returns a limited set of information based on the condition specified. In this case, only the addresses of customers who live in New York state would be returned.
Limiting a query in this manner is a good idea because it limits the results you have to process and it reduces the amount of memory being used. Many system slowdowns can be traced to bad DB queries that return too much information and consume too many resources.
To combine the information from two tables, that is, to harness the power of relational databases, you have to join the tables in the query, as demonstrated here:
SELECT Last_name, First_name, Order_Number FROM Customers, Orders WHERE Customers.id = Orders.customer_id
This should give you something that looks like the following screenshot:
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Coding Theory | Localization |
Logic | Object-Oriented Design |
Performance Optimization | Quality Control |
Reengineering | Robohelp |
Software Development | Software Reuse |
Structured Design | Testing |
Tools | UML |
Deep Learning with Python by François Chollet(12526)
Hello! Python by Anthony Briggs(9871)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9761)
The Mikado Method by Ola Ellnestam Daniel Brolund(9752)
Dependency Injection in .NET by Mark Seemann(9297)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8262)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7745)
Grails in Action by Glen Smith Peter Ledbrook(7671)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7521)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(6759)
Microservices with Go by Alexander Shuiskov(6526)
Practical Design Patterns for Java Developers by Miroslav Wengner(6422)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6401)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6383)
Angular Projects - Third Edition by Aristeidis Bampakos(5785)
The Art of Crafting User Stories by The Art of Crafting User Stories(5313)
NetSuite for Consultants - Second Edition by Peter Ries(5254)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5075)
Kotlin in Action by Dmitry Jemerov(5023)
