- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MySQL query to set different combinations for values in a table?
Let us first create a table −
mysql> create table DemoTable622 (Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,Value1 int,Value2 int); Query OK, 0 rows affected (1.08 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable622(Value1,Value2) values(1000,1000); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable622(Value1,Value2) values(2000,3000); Query OK, 1 row affected (1.04 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable622;
This will produce the following output −
+----+--------+--------+ | Id | Value1 | Value2 | +----+--------+--------+ | 1 | 1000 | 1000 | | 2 | 2000 | 3000 | +----+--------+--------+ 2 rows in set (0.00 sec)
Here is the query to MySQL combinations −
mysql> select tbl1.Id,tbl2.Value1,tbl3.Value2 from DemoTable622 tbl1,DemoTable622 tbl2,DemoTable622 tbl3;
This will produce the following output −
+----+--------+--------+ | Id | Value1 | Value2 | +----+--------+--------+ | 1 | 1000 | 1000 | | 2 | 1000 | 1000 | | 1 | 2000 | 1000 | | 2 | 2000 | 1000 | | 1 | 1000 | 3000 | | 2 | 1000 | 3000 | | 1 | 2000 | 3000 | | 2 | 2000 | 3000 | +----+--------+--------+ 8 rows in set (0.01 sec)
- Related Articles
- MySQL query to set values for NULL occurrence
- Set value only for NULL values in a MySQL table
- Set DEFAULT values for columns while creating a table in MySQL
- Set different IDs for records with conditions using a single MySQL query
- Query the database for the values not in the MySQL table?
- MySQL query for INSERT INTO using values from another table?
- MySQL query to sum 3 different values in a column displaying total of each value in result set?
- How to set all values in a single column MySQL Query?
- MySQL query to count number of duplicate values in a table column
- MySQL query to set current date in the datetime field for all the column values
- A single MySQL query to search multiple words from different column values
- MySQL query to sum the values of similar columns from two different tables for a particular ID
- Populate null columns in a MySQL table and set values
- SET only two values for all the rows in a MySQL table based on conditions?
- Insert multiple values in a temporary table with a single MySQL query?

Advertisements