Grow with Devart

Learn more about special deals for corporate clients and other benefits!

SQL CASE statement with multiple conditions

In case you need the result to satisfy multiple conditions, you can add those conditions to the CASE statement and combine them with the AND operator:

CASE expression
 WHEN condition1 AND condition2 THEN result1 
 ELSE result2 
END

You can also define a number of result values in the CASE statement by including as many WHEN/THEN statements as you want:

SELECT CASE expression
 WHEN condition1 THEN result1
 WHEN condition2 THEN result2
 ...
 ELSE result
END

Using CASE statements with the ORDER BY clause

CASE statements in the ORDER BY clause are used to change the output order and instruct the query to sort the results based on a certain requirement.

SELECT CASE expression
 WHEN condition1 THEN result1
 WHEN condition2 THEN result2
 ...
 ELSE result
END

Using CASE with the GROUP BY clause

To apply aggregate functions, you can use the CASE statement in conjunction with the GROUP BY clause.

Grouping with the CASE expression is a simple yet elegant method to arrange the query output in the required way.

SELECT CASE expression
 WHEN condition1 THEN result1
 WHEN condition2 THEN result2
 ...
 ELSE result
END

With SQL Complete, you GET

  • Code snippets for CASE expressions
  • Context-based prompts for table and column names
  • Navigation between the CASE and END keywords
  • Highlighting of matching keywords pairs
  • Quick info about database objects
  • Instant code formatter with built-in formatting profiles

Frequently asked questions about SQL Complete

Your ultimate MySQL IDE

MySQL GUI tool by Devart is an advanced IDE, whose unique features make it your perfect choice for MySQL database development and management. With smart data generation, SQL development, and comprehensive administration tools, our Studio is a viable alternative to MySQL Workbench.

dbForge Studio for MySQL

Get a free 30-day trial of dbForge Studio to evaluate all of its capabilities hidden under a sleek user interface.

Availability in the editions of dbForge Studio for MySQL

Feature

Enterprise
Professional
Standard
Express
Query Profiler
Yes
Yes
Yes
None

Copy a table with data within the same Oracle database

Step 1

Oracle provides convenient syntax that helps implement the above-mentioned scenarios. By means of the “CREATE TABLE … AS SELECT … ” command, you can create a duplicate table within the same database schema. To create an exact copy of the table preserving the table structure and all the data, execute the query as follows:

SELECT CASE expression
    WHEN condition1 THEN result1
    WHEN condition2 THEN result2
    ...
    ELSE result
END

Step 2

If you want to limit your data copying to specific columns, indicate the column names after SELECT in the following way:

CREATE TABLE new_table_name
AS
SELECT column_name1,column_name2
FROM existing_table_name;

Step 3

Provided that you have already created a table, and you want to insert the data from the existing table into it, run the following:

INSERT INTO new_table_name
SELECT *
FROM existing_table_name;

Copy a table with data within the same Oracle database

Step 4

In some cases, you may want to copy the table structure but leave out the data. Similarly, you can use the "CREATE TABLE … AS SELECT … " command, but this time you need to modify it by adding the WHERE clause that is false and, consequently, will not select any data, for instance:

CREATE TABLE new_table_name
AS
SELECT *
FROM existing_table_name WHERE 1=5;

Copy a table with data within the same Oracle database

Step 5

To copy a table from one database schema to another one, you need to apply an SQL*Plus COPY command. This powerful command allows you to actually copy data between different servers. However, we will focus on copying a table between different database schemas in Oracle. The basic syntax for the command looks as follows:

COPY FROM source_database TO target_database action -
destination_table (column_name, column_name, -
column_name ...) USING query
Let’s define the important prerequisites for using this command:
  • You need to have the access to the specified tables and know the valid credentials for the local and remote databases in the FROM and/or TO clause.
  • You can indicate the new names for the columns in the destination table, otherwise, they will have the same names by default
  • You have to choose between four actions—REPLACE, CREATE, INSERT, or APPEND, the one that suits your particular case.
  • In the USING clause, you need to write a query that will be used to specify the data for copying. Here, you are free to use any type of SELECT.
Note
Note: To create a new table and then copy the data, use CREATE; to fill the created table with data, use INSERT; to replace the created table together with its contents, use REPLACE. Besides, you can use APPEND, which works both ways: if you have created a new table, it will fill it with data; if you haven't, it will first create a table and then insert the necessary data.

Let's see an example of the COPY command that copies three columns from the source table and copies only the rows in which the EMPLOYEE_ID value is greater than 50:

COPY FROM EMPLOYEES@DB -
REPLACE DBCOPY1 -
USING SELECT FIRST_NAME, LAST_NAME, SALARY -
FROM DETAILS_VIEW -
WHERE EMPLOYEE_ID > 50

Create a duplicate table with dbForge Studio for Oracle

Running queries manually requires significant time spending, that’s why if you strive to be efficient, you will probably want to use an Oracle IDE that will help you achieve your goals within a convenient graphical user interface and boost your flexibility with an opportunity to adjust the process to your requirements.

SQL Complete is a smart solution designed to meet the increasingly sophisticated needs of SQL developers. Available as an add-in for Visual Studio and SSMS, the tool provides context-aware code completion, on-the-fly code refactoring, highly customizable code formatting, and much, much more.
SQL Complete well integrates into the IDE, significantly extending its functionality by offering a bunch of essential additional features. The solution is bound to speed up code creation and debugging as well as prevent occasional data or code losses.
dbForge Fusion for SQL Server is a multi-functional Visual Studio add-in for database development, management, and administration. The tool provides excellent SQL coding assistance and allows its users to debug T-SQL code, profile queries, manage changes, populate databases, and migrate data right in the IDE.
dbForge Fusion for SQL Server helps development teams significantly boost their productivity, improve code quality, and modernize database operations. Offering a bunch of coveted features, this powerful toolset greatly expands the limits of the IDE.
dbForge Fusion for Oracle is an advanced Visual Studio add-in that equips developers, data professionals, and DBAs with the unmatched functionality to improve their performance. The tool offers essential features that initially lack in the IDE: intelligent PL/SQL coding, Oracle PL/SQL debugger, DB change management, query profiler, etc.
Offering a set of extensive database management and administration tools that well integrate into the environment, dbForge Fusion for Oracle greatly elevates development teams productivity and lets its users go beyond the limits of the IDE.
dbForge Fusion for MySQL is a premier add-in that allows connecting and managing MySQL databases from Visual Studio. The tool is designed to push back the limits of the IDE by providing extra features: routines debugger, code completion and code formatting, query profiling, data import and export, visual query builder, and many more.
dbForge Fusion for MySQL empowers developers, DBAs, and data specialists to simplify the workflow, automate repetitive processes, reduce risks associated with changes, and significantly cut project delivery timelines.

The installation is rather simple and does not take more than a minute. Afterwards, SQL Complete becomes accessible from the menu bar of the SSMS you are using and/or Microsoft Visual Studio.

The downloaded free trial of dbForge SQL Complete is available for 14 days. When it expires, SQL Complete must be activated with the purchased activation key. To check the current status of your trial or license, go to the SQL Complete menu, point to Help, and click About.

How to Check ODBC Connection on Windows

To check the ODBC connection status in Windows you can use the ODBC Data Source Administrator tool corresponding to your application bittness (32-bit or 64-bit):

DBMS vs RDBMS: a detailed comparison

Now let's proceed to a more detailed comparison; and here it makes sense to compare the basic capabilities of relational and non-relational database models and the way they manage and store data.

Parameter Non-relational DBMS RDBMS
Database structure Hierarchy (parent-child relationship), network (many-to-many relationship), or a collection of objects Tabular format (rows and columns)
Data storage Data is stored in files Data is stored in inter-related tables (see above)
Data access One user at a time Simultaneous access by multiple users with varied user roles
Data inter-relations None Relations between tables via foreign keys
Unifying language None SQL (Structured Query Language)
Data redundancy Common Eliminated with keys and indexes
ACID properties: Atomicity, Concurrency, Isolation, Durability No compliance Full compliance
Client-server architecture No Yes
Distributed databases No Yes
Handling of large amounts of data No Yes
Normalization No Yes
Hardware and software requirements Low Higher

Entity Framework Core Architecture

As we mentioned earlier, Entity Framework Core was born in 2016, but years have passed since then. By this time, we have witnessed several EF Core versions. For your convenience, we have compiled a table with brief information about them.

Version Release Date Description
EF Core 1.0 27 June 2016 First version after EF 6
EF Core 2.0 14 August 2017 Released with Visual Studio 2017 15.3 and ASP.NET Core 2.0
EF Core 3.0 23 September 2019 Released with Visual Studio 2019 16.3 and ASP.NET Core 3.0
EF Core 3.1 3 December 2019 Preferred long-term supported version until at least 3 December 2022.
EF Core 5.0.2 12 January 2021
EF Core 6.0 10 November 2021 Latest available version

At the point of writing this article, the latest available version is EF Core 6.0.7. Here is a short list of the changes in this version:

  • SQL Server temporal tables
  • Migration Bundles
  • Pre-convention model configuration
  • Compiled models
  • Improved performance on TechEmpower Fortunes
  • Improvements to scaffolding from an existing database
  • LINQ query enhancements
  • New mapping attributes
  • Model building improvements
  • DbContext factory improvements
  • Miscellaneous improvements

See the differences in code before and after formatting

SQL Complete helps you create, customize, and switch between formatting styles, share them with your colleagues, as well as manage and easily format SQL scripts by applying various formatting options.

Lorem ipsum dolor sit amet

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco

CREATE operation

The letter 'C' in the CRUD acronym refers to the CREATE operation that implies adding rows and columns to a table. In SQL Server, the INSERT statement can be used to create new records in the table. The syntax of the INSERT INTO statement would be:

INSERT INTO table_name (column1,column2,….)
VALUES (value1,value2,….)

Keep in mind that INTO is optional and can be omitted. As you can see, you need to specify the name of the table to be populated with records and a list of columns along with their values. Now, let’s try to insert data into the Persons table.

CREATE query example

In the example, we add multiple rows to the Persons table by executing the INSERT INTO query:

INSERT INTO dbo.Persons
(
PersonID
,LastName
,FirstName
,Address
,City
)
VALUES
(1,'Conrad','Baumann','1388 Parkwood Loop, STE 31','Lansing'),
(2, 'Adam', 'Reyes', '56 Front Way', 'Salem'),
(3, 'Keira', 'Delacruz', '2676 E Prospect Hill Ave', 'Lincoln');
GO

READ operations

The letter 'R' in the CRUD acronym refers to the READ operation that retrieves data from the table using the SELECT statement. We can either fetch all data from the table or retrieve data filtered by the condition criteria in the WHERE clause.

The syntax of the SELECT statement would be:

- - syntax to retrieve all data from the table
SELECT * FROM table_name
- - syntax to retrieve filtered data from the table
SELECT * FROM table_name WHERE condition
READ operation example

After we inserted new records into the Persons table, we can retrieve data to make sure that the rows have been added to the table. To fetch data from the table, we execute the following statement:

SELECT * FROM AdventureWorks2019.dbo.Persons

The result shows that all values for each record in the table have been inserted.

READ operation example

Now, we change the query to view in the output only data that matches the condition in the WHERE clause. For example, we want to see information only about Conrad Baumann. To do that, run the following query:

SELECT
*
FROM AdventureWorks2019.dbo.Persons
WHERE PersonID = 1;

As you can see, the query returned the record according to the specified condition.

READ operation example

Let's go on to have a look at the CRUD UPDATE operation.

UPDATE operations

The letter 'U' in the CRUD acronym refers to the UPDATE operation that modifies the existing records in a SQL table. Thus, to make changes to data, you can use the UPDATE statement with the following syntax:

UPDATE table_name
SET column_1=value_1,column_2=value_2
WHERE condition;
UPDATE statement example

Suppose that Conrad Baumann moved to another place and we need to update his address. To modify values, we execute the UPDATE query:

UPDATE AdventureWorks2019.dbo.Persons
SET
Address = '1399 Firestone Drive'
WHERE
PersonID = 1

To check that the changes have been applied to the table, we execute the SELECT statement:

UPDATE statement example

The result in the screenshot verifies that the specified row has been updated.

DELETE operations

The last letter 'D' in the CRUD acronym refers to data deletion. In SQL, it means deleting records from a SQL table by executing the DELETE statement. We can remove either all records or specific ones from the table. In the latter case, we can specify which rows to remove in the WHERE clause.

The syntax of the DELETE statement would be:

- - syntax to delete all records from the table
DELETE FROM table_name
- - syntax to delete specified records from the table
DELETE FROM table_name WHERE condition

Table_name is the table from which data should be deleted.

DELETE statement example

In our example, we need to remove information about Conrad Baumann because he has retired. To do that, we execute the statement with the WHERE clause in which we set a condition:

DELETE FROM AdventureWorks2019.dbo.Persons
WHERE
PersonID = 1;
GO

If we retrieve the updated data, we'll see that the specified record has been deleted from the table.

DELETE statement example

To remove all records from the Persons table, we execute the following DELETE query:

DELETE FROM AdventureWorks2019.dbo.Persons

This way we considered how CRUD operations work in SQL Server: In order to add, update, or remove data we needed to write statements each time. As you can notice, this may take a lot of time and effort. But that can be worked around and we’ll show how to do it.

Competitors vs. Delphi Programming

Understanding what kind of programming language is Delphi comes easier when you compare it with other popular languages.

dbForge SQL Tools

Enhance SSMS with essential add-ins and tools including Source Control. Boost any database task.
SAVE UP
TO $1869

ODBC Drivers

Reliable and simple to use data connectors for ODBC data sources. Compatible with multiple third-party tools.

Interested? Contact us!

Fill out the form and allow us some time. We will get in touch once your request is validated.

Still doubt that you need dbForge Studio for MySQL?

with benefits, challenges, and best practices
Guide devops

Need a product to manage your MySQL database?

Get the most advanced development and administration GUI tool - dbForge Studio for MySQL

Who can qualify for our programs?

Non-profits

NGO staff

Do you work for a non-profit organization or an NGO? We truly believe your efforts require our support and are committed to making a paid plan easier for you. Contact us to discuss your needs.

Students & teachers

Students & teachers

At Devart, education is a big part of our mission. We have special offers for both senior students and teachers of different educational institutions. Just get in touch with us and save on licenses.

Big purchase

Bulk purchasers

Good stuff is even better in bulk. Same deal with our licenses. We offer significant discounts to customers making bulk orders. Just pick the products of interest and reach out for a granted discount.

Students & teachers

Switching customers

Our new customers—those who have tested our competitors' tools and chose to stay with Devart—are eligible for a price cut. We value that and share 50% discounts for your competitor upgrade.

Microsoft & Oracle experts

Microsoft & Oracle experts

Free licenses are granted for developers with Microsoft MVP, Oracle ACE, Embarcadero MVP. Your skills and experience matter for us, and we will be truly grateful for your valuable feedback.

Oracle Database users

Oracle, due to its popularity, is a favored choice of database experts who focus on different areas of database use.
Software developer
Software developer
Creates applications that use databases as their backgrounds
Database Administrator
Database Administrator
Administers and maintains database
Data analyst
Data analyst
Analyzes data to identify important patterns and retrieve valuable business insights
Database developer
Database developer
Designs and manages database schemas and all components
DevOps engineer
DevOps engineer
Configures, elaborates, and supports data pipelines
Data architect
Data architect
Designs, develops, and handles data infrastructures