![]() Feel free to experiment and add new strings and characters. ![]() Mysql> SELECT employeeid, CONCAT(firstname, lastname) AS employee_name FROM employee Īs we can see that a space is missing between the firstname and the lastname so, we will include a space character between the two in the CONCAT. In the following example we are concatenating firstname and lastname column value and giving it a new name employee_name. We use the CONCAT() function to concatenate columns in MySQL. Mysql> SELECT employeeid AS id, firstname, lastname FROM employee We can use the SELECT statement to retrieve specific columns. In the following example we are giving the employeeid column a new name id. In general, parentheses can be ignored in join expressions containing only inner join operations. INNER JOIN is used with an ON clause, CROSS JOIN is used otherwise. In standard SQL, they are not equivalent. ![]() USE databasename For example, the following statement set the current database to companydb in MySQL. In MySQL, JOIN, CROSS JOIN, and INNER JOIN are syntactic equivalents (they can replace each other). We can given new names to the columns in the SELECT query by using AS followed by the new name. To select a database, we need to use the USE statement. Mysql> SELECT commentid, commentbody FROM comments Similarly, in the following example we are selecting commentid and commentbody from the comments table. Mysql> SELECT employeeid, firstname, lastname FROM employee In the following example we are selecting employeeid, firstname and lastname of all the employees from the employee table. We may not want to retrieve all the columns of a table all the time so, instead of passing the * we mention the name of the columns that we are interested in. | commentid | employeeid | commentbody | lastmodified | created | In the following example we are selecting all the columns of the comments table. Databases store data for later retrieval. | employeeid | firstname | lastname | email | score | birthday | lastmodified | created | SELECT QUERY is used to fetch the data from the MySQL database. In the following example we are selecting all the columns of the employee table. The output file is a CSV (Comma Separated Values) file. mysql> SELECT INTO OUTFILE '/tmp/cars.txt' -> FIELDS TERMINATED BY ',' -> LINES TERMINATED BY ' ' -> FROM Cars Query OK, 8 rows affected (0.00 sec) We write data from the Cars table into a cars.txt file. We use the SELECT * FROM table_name command to select all the columns of a given table. The SELECT statement can be used to write data from tables to a file. We will be using the employee and comments table that we created in the CREATE Table tutorial. Inside a table, a column often contains many duplicate values and sometimes you only want to list the different (distinct) values. In this tutorial we will learn to select data from tables in MySQL. The SELECT DISTINCT statement is used to return only distinct (different) values.
0 Comments
Leave a Reply. |