Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,208,034 members, 8,001,161 topics. Date: Wednesday, 13 November 2024 at 04:32 AM |
Nairaland Forum / Science/Technology / Programming / How To Query A Database Using Select With Mysql (862 Views)
[Help Request]How Do I Upload Images Into My Database using Visual Basic? / ''no Row At Position 0'' When Retrieving Image From An Sql Database Using Vb.net / Connecting To A Database Using Visual Basic (2) (3) (4)
(1) (Reply)
How To Query A Database Using Select With Mysql by nateone(m): 2:41pm On Jul 21, 2008 |
The most basic operation in any SQL system is the SELECT query. In MySQL, programmers use SELECT to query a database in order to retrieve records. Using SELECT will return a number of rows from a database based on the criteria you pass it. The command can be basic or complicated depending on how enhanced your SELECT statements are. Step1 Gather some basic information about the data you want. Know what information the database hold as well as which table you want to query, what rows the table holds and which of those rows you want to see. Step2 Start with a very simple query which can then be built upon. This query will return every column and every row of the "customers" table, showing the basic form of the SELECT command. The amount of data returned will be overwhelming if your customer table is large. Example: SELECT * FROM customers; Step3 Define what it is you want to do with the information your query will return. Remember, you won't usually need all columns of data. Step4 Return only wanted columns. To return only a few columns, replace the asterisk in the previous command with a comma-separated list of columns you want. For example, if you're doing a mailing to all of your customers, you will only need the name and address columns. Example: SELECT name,address FROM customers; Step5 Narrow your query further by returning only rows that interest you, using a WHERE clause. The WHERE clause will cause the SELECT query to return only rows that satisfy the WHERE clause. This query will select the name, address and balance of every row in the database with a negative balance. Example: SELECT name,address,balance FROM customers WHERE balance < 0; Step6 Use the boolean OR and AND with the WHERE clause to join any number of conditions. The conditions can be as complicated or simple as you need them to be. It's dependent on how specific you want the return to be. Here AND is used so that the query will select not only the name and address of everyone with a positive balance, but also those whose name is 'Joe Smith'. Example: SELECT name,address FROM customers WHERE balance > 0 AND name = 'Joe Smith'; # In MySQL, as in other programming languages, the asterisk ( # ) is a wild card used as a shortcut to return all the columns from a table. www.flyhow..com |
(1) (Reply)
I Need Someone To Design A Database Driven Website. / Help With Database Development. / Programmers Wealth Hive
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 15 |