|
| ||||||||||
| Tags: algorithm, database, innodb, mysql, sql |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Interrogating database with the query in MySQL
Code: SELECT * FROM table_name SELECT COUNT (*) FROM table_name Code: SELECT COUNT (*), MAX (Column1) FROM tablename WHERE column2 = value |
|
#2
| |||
| |||
| Re: Interrogating database with the query in MySQL
In this case we will always have a line, because even here we used functions of the column. The columns, however, will be two, because we asked two values: the number of rows and the maximum value of Column1. The presence of the WHERE clause causes are included in the count only the rows where the value in column2 is the same as specified. Let's look at the syntax of the SELECT (some terms are omitted for simplicity): Code: SELECT
[ALL | DISTINCT | DISTINCTROW]
expression, ...
[INTO OUTFILE 'file_name' options
| INTO DUMPFILE 'file_name']
[FROM tables
[WHERE conditions]
[GROUP BY {column_name | expression | position}
[ASC | DESC], ... [WITH ROLLUP]]
[HAVING conditions]
[ORDER BY {column_name | expression | position}
[ASC | DESC], ...]
[LIMIT [offset,] row_number]
Code: SELECT NOW () |
|
#3
| |||
| |||
| Re: Interrogating database with the query in MySQL
The terms that will form the columns in output may refer to columns of tables referenced, but can also be obtained with functions applied to columns, or mathematical expressions, or functions that return values are independent (as in the case of NOW ()). We have already seen that if we use the so-called functions column we will have a unique value that is n rows. Therefore we can not have a regular column name (scalar) function next to a column: Code: SELECT Column1, max (column2) FROM table_name Code: SELECT category, max (salary) FROM employees GROUP BY category |
|
#4
| |||
| |||
| Re: Interrogating database with the query in MySQL
INTO OUTFILE is used to write the table result to an output file that will be created on the server (you can not use a file name already exists). The options are the same FIELDS and LINES already seen for LOAD DATA INFILE, which is complementary SELECT INTO OUTFILE. To use this clause requires the FILE privilege. If instead of using INTO DUMPFILE INTO OUTFILE, the output file will contain a single line, without delimiters or rows and columns without escape characters. The clause indicates the table or tables from which data will be extracted. The simplest queries extract data from one table, but it is very often need to combine multiple tables. In this case you make a JOIN. > As each table belongs to a database, the full form is name_database.name_table.If you do not specify a database name implies is the use of the current database. In addition to any table we can associate an alias to refer to the rest of the query, via the AS clause. The WHERE clause determines the conditions to be applied to each row of the input table to decide if that line will be part of the result. The GROUP BY, as we have seen, is used to group the results on the values of one or more columns. The result table will be sorted according to these values. If we add the WITH ROLLUP, we will get the extra lines with the total figures for each break value of the fields together. The HAVING clause plays a selection of the lines, just like the WHERE clause. The difference is that the WHERE clause is applied to the rows of the original tables, while the HAVING clause is applied to the rows in the result table after the groupings required by the GROUP BY clause. In practice, it is useful to test the values returned by the column. With ORDER BY values indicate on which order the output. If we add the values DESC are sorted in descending order, while the default is ascending. If we do not use the ORDER BY order of the results will be undefined (unless you use GROUP BY). The LIMIT clause, then, limits the number of rows to be returned. When used with a single parameter, the maximum number of rows returned from the first. When used with two parameters, the first indicates the starting line (the first line is equal to 0), while the second is the maximum number of rows. |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Interrogating database with the query in MySQL" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| MySQL query in a query | Rail racer | Software Development | 3 | 21-07-2009 07:06 PM |
| Turn on MySQL query cache to speed up query performance | DMA2Superman | Software Development | 3 | 07-07-2009 10:26 AM |
| Use variables in a MySQL query | Chrisch | Software Development | 3 | 25-04-2009 12:11 PM |
| MySQL IF ELSE in Query | Ryder | Software Development | 3 | 27-03-2009 05:24 PM |
| MySQL UPDATE Query | ANDERS | Software Development | 2 | 10-02-2009 10:57 AM |