
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Show a MySQL user-defined variables values in the result table?
Use @ for variable and concat_ws() to display concatenated result in the table. Let us first create a table −
mysql> create table DemoTable1508 -> ( -> StudentFirstName varchar(20), -> StudentLastName varchar(20) -> ); Query OK, 0 rows affected (0.55 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1508 values('Chris','Brown'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1508 values('David','Miller'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1508 values('John','Doe'); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1508;
This will produce the following output −
+------------------+-----------------+ | StudentFirstName | StudentLastName | +------------------+-----------------+ | Chris | Brown | | David | Miller | | John | Doe | +------------------+-----------------+ 3 rows in set (0.00 sec)
Here is the query to show a MySQL variable in the result table −
mysql> select @FullName:=concat_ws('-',StudentFirstName,StudentLastName) from DemoTable1508;
This will produce the following output −
+------------------------------------------------------------+ | @FullName:=concat_ws('-',StudentFirstName,StudentLastName) | +------------------------------------------------------------+ | Chris-Brown | | David-Miller | | John-Doe | +------------------------------------------------------------+ 3 rows in set (0.03 sec)
- Related Articles
- Using User-Defined Variables in MySQL
- User-defined variables vs Local Variables in MySQL?
- System variables vs User-defined variables in MySQL?
- How can I return a record from a table nearest to a user-defined variables value in MySQL?
- Set user-defined variable with table name in MySQL prepare statement?
- Increase database field value by specified percentage using user-defined variables in MySQL
- Updating a MySQL table row column by appending a value from user defined variable?
- Select into a user-defined variable with MySQL
- In MySQL, why a client cannot use a user-defined variable defined by another client?
- Perform MySQL SELECT INTO user-defined variable
- How to display grant defined for a MySQL user?
- Add user defined value to a column in a MySQL query?
- SHOW TABLE statement with multiple LIKE values in MySQL?
- MySQL ORDER BY with numeric user-defined variable?
- What are the properties of MySQL user variables?

Advertisements