SQL Articles

Page 5 of 12

How to Specify a Date Format on Creating a Table and Fill it in SQL?

SQL
Golden_Beach
Golden_Beach
Updated on 19-Sep-2024 955 Views

In SQL, date and time values are handled using specific data types, such as DATE, DATETIME, TIMESTAMP, etc. Each database management system (DBMS) may have its conventions for date formats, so understanding how to specify and use these formats is essential for working with dates in SQL. The following are the data types to handle date and time in SQL: DATE: Stores date values (year, month, day). DATETIME: Stores date and time values (year, month, day, hour, minute, second). TIMESTAMP: Stores date and time values, ...

Read More

SQL Query to Check if Date is Greater Than Today in SQL

SQL
Mithlesh Upadhyay
Mithlesh Upadhyay
Updated on 10-Sep-2024 787 Views

You can handle and manipulate date and time values within a database using SQL queries. You need to filter records based on date comparisons, like checking if a date is greater than today. We will query this using our own sample data as given below. Date Comparisons You can use various comparison operators, like >, =, and CURRENT_DATE; Here, date_column is the field containing the date values you want to compare. “CURRENT_DATE” is a keyword in SQL that represents the current date. Example Consider you have created a table named EVENTS using the CREATE TABLE statement as ...

Read More

How to Find Nth Highest Salary in SQL

SQL
bhavesh somani
bhavesh somani
Updated on 06-Aug-2024 6K+ Views

In this article, we will write an SQL(Structured Query Language) query to find the Nth highest salary from a database table. We can obtain the 2nd highest salary, 3rd highest salary, and so on. Certainly, This is the most commonly asked question in an interview. There are different methods to achieve this, we will understand every technique in detail. Problem Statement Assume we have a table named employees with 3 columns namely, EmployeeId, EmployeeName and, EmployeeSalary as shown below − EmployeeId EmployeeName EmployeeSalary 10001 Mahesh 33000 10002 John 35000 10003 Abdul 34500 ...

Read More

Production databases in SQL queries

sudhir sharma
sudhir sharma
Updated on 28-Jun-2024 527 Views

Overview Production databases are crucial for storing and retrieving data in organizations. SQL queries are essential for efficiently retrieving specific information from these databases. The article aims to equip readers with practical knowledge for working with production databases using SQL queries. Understanding SQL Queries and Relational Databases Relational databases provide a structured framework for organizing and storing data efficiently. Data modeling techniques, including normalization, help in designing effective databases. Understanding these concepts is essential for writing SQL queries that retrieve information accurately and efficiently from complex databases. Let’s dive into a few real world examples − Example 1 Creating ...

Read More

SQL Query to Convert Rows to Columns in SQL Server

Bharti Kumari
Bharti Kumari
Updated on 22-Oct-2023 32K+ Views

Introduction The PIVOT operator is used to rotate rows of a table into columns. It is useful for generating cross-tabular reports, where the results are presented in a summary form. The PIVOT operator is available in SQL Server 2005 and later versions. The PIVOT operator is used to convert rows into columns in a SQL Server database. It is often used to generate cross-tabular reports, where the results are presented in a summary form. Definition In SQL Server, the PIVOT operator allows you to convert rows into columns. It is useful for generating cross-tabular reports, where the results are ...

Read More

How to Update Two Tables in One Statement in SQL Server?

Bharti Kumari
Bharti Kumari
Updated on 14-Sep-2023 53K+ Views

Introduction In SQL Server, you may sometimes need to update data in multiple tables at the same time. This can be done using a single UPDATE statement, which allows you to update multiple tables in a single query. To update two tables in one statement, you can use the UPDATE statement with a JOIN clause. The JOIN clause allows you to specify a relationship between the two tables that you want to update, based on a common column or set of columns. Definition The term "update two tables in one statement" refers to the process of using a single UPDATE ...

Read More

How to Convert Epoch Time to Date in SQL?

Bharti Kumari
Bharti Kumari
Updated on 02-Sep-2023 72K+ Views

Introduction The epoch is the date and time relative to which a computer's clock and timestamp values are determined. Epoch time is commonly used in computer systems to represent a point in time. It is typically represented as a single integer value, which represents the number of seconds that have elapsed since the epoch. In SQL, you can convert an epoch time value to a date by using the to_timestamp() function. This function converts an epoch time value (which is typically stored as a BIGINT or INT data type) to a timestamp with time zone value. The resulting timestamp value ...

Read More

Data anomalies in DBMS

Amrendra Patel
Amrendra Patel
Updated on 22-Aug-2023 19K+ Views

Anomalies means problems or inconsistency which happened during the operations performed on the table. There can be many reasons that anomaly occur for example, It occurs when data is stored multiple times unnecessarily in the database i.e. redundant data is present or it occur when all the data is stored in a single table. normalization is used to overcome the anomalies. the different type of anomalies are insertion, deletion and updation anomaly. Input The same input is used for all three anomalies. Student ID Name Age Branch Branch_Code Hod_name 1 A 17 Civil 101 Aman ...

Read More

Current user function in SQL

Amrendra Patel
Amrendra Patel
Updated on 22-Aug-2023 657 Views

It is used to return the name of the current user in sql database server. it does not accept any parameter. Syntax CURRENT_USER Current_user is the function used to get the name of current user Example 1 In this example, we are going to use the current_user function to get the current user name. Input Employee Emp_id Name Dept_name Salary 1 Monu IT 50000 2 Sonu HR 60000 3 Golu Security 70000 This database is currently used by amrendra. Code SELECT CURRENT_USER;#selected current user name Output Amrendra ...

Read More

Creating materialised view using table definition in cassandra

Amrendra Patel
Amrendra Patel
Updated on 22-Aug-2023 184 Views

A materialised is defined as a database object that contains the results of a particular query. It could be called as a subset of a table. Any changes in the base table would be reflected in the materialised view. Syntax CREATE MATERIALISED VIEW view_name AS SELECT * FROM table_name WHERE column_name IS NOT NULL PRIMARY KEY (provide_primary_key) Here, view_name is the name of the materialised view, table_name is the base table, column_name are the columns provide_primary_key are the primary keys for the base table. Example 1 In this example, we are gonna have a ...

Read More
Showing 41–50 of 115 articles
« Prev 1 3 4 5 6 7 12 Next »
Advertisements