Trending March 2024 # Usage And Different Examples Of Sql Max() # Suggested April 2024 # Top 11 Popular

You are reading the article Usage And Different Examples Of Sql Max() updated in March 2024 on the website Bellydancehcm.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested April 2024 Usage And Different Examples Of Sql Max()

Introduction to SQL MAX()

SQL MAX() is one of the aggregate functions available in SQL that helps us fetch the greatest value among multiple values specified in the column values of records, the expression consisting of the column that is mentioned. When a query is used to retrieve the data that report related and contains a group by a statement, the MAX() function is used to get the greatest value of a particular column or columns based on the grouping function.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Syntax and Usage

The syntax of the MAX function in SQL is given below:

SELECT MAX(expression) FROM table_name [WHERE restriction];

Where expression can be any name of the column of the table or a formula built up using column names and static literal values or variables, the table_name is the name of the table from which you want to retrieve the records and calculate the greatest value from one of their columns. The use of the FROM table name clause is required. One optional thing is the use of a where clause to mention the conditions and restrictions that the records of the table should fulfil to consider that record’s column value for fetching the greatest value.

Examples of SQL MAX()

Given below are the examples of SQL MAX():

Example #1 – Using a single column.

Let us firstly consider a simple example that we used above. We will calculate the greatest value of SQL numbers using the MAX() function. Let us create one simple table named numbers and store the num column value in it.

We will use the following query statement to create our table.

Code:

CREATE TABLE numbers (num INT) ;

Now, we will insert the above records in the table.

Code:

INSERT INTO numbers(num) VALUES (50), (100), (150), (200);

Let us now retrieve the records once.

Code:

SELECT * FROM numbers ;

Output:

Now, we will calculate the greatest of num column of numbers table using MAX() function using the following query statement.

Code:

SELECT MAX(num) FROM numbers ;

Output:

Example #2 – Using the distinct function.

We can use the distinct function in MAX() function to consider the column’s repetitive values only once while fetching the greatest value. Suppose that we insert some more records in the numbers table using the following query statement.

Code:

INSERT INTO numbers(num) VALUES (350), (800), (150), (300),(450), (100), (250); select * from numbers;

If we use SELECT MAX(num) FROM numbers; statement to calculate the greatest value of num column, then each of the values will be considered while fetching the greatest value.

Code:

SELECT MAX(DISTINCT(num)) FROM numbers ;

The output will be the same as that of the first query without a distinct function but internally the calculation of greatest value by MAX() function will only consider the column values that are repeated such as 100 and 150 only once.

The output of both of the above queries is as shown below.

Output:

Example #3 – Using formula.

We can use the MAX() function expressions to consider the value evaluated by fetching each of the formula or expression values containing column value to calculate the greatest value.

Let us consider one example; we will calculate the greatest of all the columns after they are multiplied by 10 and added by 1.

Code:

SELECT MAX((num * 10) + 1) FROM numbers ;

Output:

We can even use the existing functions such as SUM() and COUNT() inside the MAX() function.

Example #4 – Using group by.

When we have complex tables and relations between multiple tables, we have to query those tables using joins to retrieve data, usually for reporting purposes that consist of summarized data. Even in some scenarios, the data from a single table need to be manipulated to get summarized data. Suppose that we have one table named workers consisting of the following records in it that are retrieved by executing a simple select query on that table.

Code:

SELECT * FROM workers;

Output:

Now, the situation is such that we have to calculate the greatest salary of the workers per team. The output should consist of the team id and the greatest salary of that team. For this, we will have to use the group by statement and group the records based on team id and calculate the greatest salary by using MAX() function.

Code:

SELECT team_id, MAX(salary) FROM workers GROUP BY team_id ;

The execution of the above query statement will give the following output along with team ids and their respective greatest salaries.

Output:

Conclusion

We can use the MAX() function in SQL to fetch the greatest value of the columns of the tables or greatest of expressions that involve column values and even calculate the greatest value of columns in the grouped manner using the GROUP BY statement.

Recommended Articles

We hope that this EDUCBA information on “SQL MAX()” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

You're reading Usage And Different Examples Of Sql Max()

Syntax And Different Examples Of Jquery Innerwidth()

Introduction to jQuery innerWidth()

jQuery innerWidth() is an inbuilt jQuery method. It gives the current computed inner width for the first matched element and sets the width for each matched element. This method is supported by browsers- Google Chrome, Internet Explorer, Firefox, Opera, Safari.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

The method innerWidth() method includes the padding value but excludes the margin and border value as represented in the below diagram.

Syntax of jQuery innerWidth()

Syntax Parameter Description Value Type Version

$(selector).innerWidth() NA NA 1.0

$(selector). innerWidth (Value) 1. Value: A numerical value as the measurement value. 1. Handler: String/Number 1.8.0

$(selector). innerWidth (Function) 1. Function: To set the width of the matched element whose index is given as an input argument. 1. Function: Function 1.8.0

Examples of jQuery innerWidth()

Given below are the examples of jQuery innerWidth():

Example #1: Without using any parameter

innerWidth() method can be used without providing any input argument. It is used to get the width measurement for the first matched element including the padding value. This method without input argument becomes a read-only property of the window.

Code:

<script type = ”text/javascript” $(document).ready(function() { var color = $(this).css(“background-color”); var width = $(this).innerWidth(); $(“#result”).css({‘color’: color, ’background-color’:’white’}); }); }); #div1 { margin:10px;padding:12px; border:3px solid #666; width:60px;} #div2 { margin:15px;padding:6px; border:5px solid #666; width:60px;} #div3 { margin:20px;padding:12px; border:3px solid #666; width:60px;} #div4 { margin:15px;padding:6px; border:5px solid #666; width:60px;}

Output:

Before innerWidth() method is called:

After innerWidth() method is called:

Example #2: With the ‘value’ parameter

For jQuery innerWidth(), a value of type string or number can be given as input argument value. This syntax can be used to modify the width of the selected element to the value that is passed to the method as input argument value.

Code:

$(document).ready(function(){ $(“div”).innerWidth(500) $( ”p” ).text( ”InnerWidth for div session:” + $( ”div” ).innerWidth() ); }); });

Output:

Before innerWidth() method is called:

After innerWidth() method is called:

Note: For the syntax innerWidth(value), if a number is provided as value, jQuery treats in terms of pixel unit by default unless any specific unit is not mentioned. If a string value is provided, any CSS measurement can be used for the width value.

Example #3: innerWidth() With ‘function’ parameter

In this syntax, the method innerWidth() accepts function as input argument. This syntax of innerWidth() method accepts any function that is with or without input arguments.

Code:

//The width of the div element is decided by the function output of myfunc() and $(document).ready(function(){ $(“div”).innerWidth(myfunc()); $( ”p” ).text( ”InnerWidth for div session:” + $( ”div” ).innerWidth()); }); }); function myfunc() { return 100+$( ”div” ).innerWidth() }

Output:

Before innerWidth() method is called:

After innerWidth() method is called:

Screen 1: myfunc method is called once.

Screen 2: myfunc method is called twice.

Additional Note

This method returns the value of the inner width in terms of pixels.

In the case of an empty set of elements, the method gives the result as ‘undefined’.

This method does not support .doc or window object. For such an object. width() method is used.

The resultant value can be fractional as well. If the code takes the round value for the result, it may give incorrect dimensions for the site in the zoomed condition as the browser may not include any API to detect such condition.

If the matched element or its parent element is in hidden state, innerWidth() may not give an accurate result. In order to avoid such erroneous result, it is required to ensure the visibility state of the element to be true then revert back to the hidden state after the method execution is completed. Though it works for accuracy, still reliability of this approach is under question mark.

InnerWidth(), OuterWidth() and Width() are similar to each other. They are different from each other in terms of inclusion or padding, margin and border values. InnerWidth() includes padding value only where as OuterWidth() includes both padding and border value. Width() does not consider only element width.

Recommended Articles

This is a guide to jQuery innerWidth(). Here we discuss the introduction, syntax, and examples of jQuery innerWidth(). You may also have a look at the following articles to learn more –

jQuery remove()

jQuery wrapInner()

jQuery fadeIn()

jQuery appendTo()

Learn The Examples Of Sql Extensions

Introduction to SQL extensions

A sql extensions is a file extension used for files containing standard query language(SQL) queries and commands to create and modify relational database objects. It is identified as .sql type. The SQL file format is written in ASCII. For the uninitiated, it can be considered a flat-file with nothing but a set of SQL statements. For example, statements for creating, inserting, extracting, updating, or deleting a data table in SQL databases. It does not contain the entire database in it.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

You must be wondering when and how we are going to use the SQL extension. The most frequent use of the .sql extension is when we have to run certain queries multiple numbers of times. Imagine writing the same query those many times. It’s terrifying right. We can instead save the query with .sql extension and open, re-run or edit it n number of times without having to rewrite the entire query again and again. Another important usage of sql extension is backing and restoring database backups. Some database servers such as SQL Server and MYSQL support this. One more prominent usage of .sql extension is exporting and sharing user-defined schemas, functions, procedures, and triggers with other users.

Examples of SQL extensions

Next, let us cover some fundamentals such as creating and opening a file with sql extension.

Example #1 – Creating a sql file extension

CREATE DATABASE Test_db;

Having created the database, let us create a table called “cities” in it that contains a list of cities with their ids and country. Here is the create table statement for the city table.

CREATE TABLE cities ( id int NULL, country varchar (50) NULL, city varchar (50) NULL );

Now we are all set to script this create table statement using extension so that we can reuse the code. Follow the following steps for more.

Step 1: Go to object explorer

Step 2: Select the desired database

Step 3: Select the table which you want to script

Here is an image to illustrate the flow.

Once you are done with navigation, move to step 4.

Step 4: SELECT the desired statement that has to be scripted.

Step 5: Choose a file from the next menu and save the script with the desired name. Here, the file of the extension type by default. If that’s not the case for you, mention .sql as a file extension.

Example #2 – Opening a sql file extension

Opening a file of the sql extension type is as easy as creating one. You just follow the following steps.

Step 1: Go to File Menu

A dialog box as shown below will appear in front of you.

The file of the sql extension type will have the following statements. It is basically the CREATE To script for the cities table. Just run this script to create the table.

USE [Test_db] GO /****** Object:  Table [dbo].[cities]    Script Date: 07/10/2024 12:04:49 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[cities]( [id] [int] NULL, [country] [varchar](50) NULL, [city] [varchar](50) NULL ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO

We have successfully created the table from a script (a file of sql extension type).

Example #3 – Working with .sql files

Suppose we do not have access to the Server query editor, but we want to write a query to insert a few records into the cities table. We can use text editors such as notepad, notepad++, atom, sublime, vim, etc. to view, write, or edit .sql files.

INSERT INTO [Test_db].[dbo].[cities] ([id] ,[country] ,[city]) VALUES (1,'India', 'New Delhi'), (2,'U K','London') GO

Having successfully written and saved the query in the text editor, the next task is to open the file. So open the .sql file in the server as discussed above. The query will be automatically opened in the query editor as shown below.

Now execute the query to insert records in the city table. Let us check using a SELECT statement if the data has been successfully entered.

SELECT * FROM cities;

Yes, it has been successfully populated. If you wish to re-run the same SELECT query or share it with your teammates, just save it (by pressing Ctrl + S or from the file menu). Again a dialog box as shown below will appear.

Just save it and you are good to go.

Conclusion

SQL extension is a file format that is used to store and save sql commands, queries, functions, triggers, etc. so that they can be reused and shared.

Recommended Articles

We hope that this EDUCBA information on “SQL extensions” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

Learn The Different Examples Of Python Widgets

Introduction to Python Widgets

Widgets are small parts on web applications that allow user input. The widgets are eventful objects of Python that have a browser representation, often as control such as a slider, textbox, etc. Interactive GUIs for Python notebook are created using these Widgets. Synchronize stateless and stateful information between JavaScript Python and is done using widgets. Widget input allows us to add parameters and dashboards to the notebooks. Widget API has calls that can be given with various types of input, access bound values, and removing them. Exploration of different parameters using a single query are the results of widgets. Widgets are of many types. Few are Text, drop down, Combo box, Multi-select, which are widely used. All these widgets are quiet neat to understand and implement.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax of Widgets

import widget_name

Example:

Ipywidgets packages furnish a lot of common interface controls. These interfaces are used in exploring code and data interactively. These can be customised and assembled for creating user interfaces that are complex. Let’s see various schemes to create user interfaces using Python Ipywidgets. The package of widgets in Python can be installed in Anaconda by default. Manual installation is done with conda install Ipywidgets. Or you can also use pip install Ipywidgets, but then an extension for Jupyter Notebook is needed.

Now, getting into the actual methodology:

The block of code shows how we import the widgets. These are few widgets which are used in general.

Code:

import Ipywidgets as widgets from Ipywidgets import Hbox, Vbox import numpy as np import matplotlib.pyplot as plt from Ipython.display import display %matplotlib inline Examples of Python Widgets

Widgets have an @interact decorator, which controls the function of arguments. The f() function receives an integer as an argument. That displays a slider by default.

Example #1

Displaying a slider which has border values and can be slid along, which is an integer slider.

Code:

import Ipywidgets as wg import Ipython.display name = chúng tôi (value = ‘Name’) age = wg.IntSlider (description = ‘Age: ’) display (name, age) print (name.value + ‘ is already ‘+ str (age.value) + ‘ now ’)

Output:

The above displays an age bar or a slider, where you can slide the age of John and hold at one. It is still changeable. At age.value, you need to consider taking the value as a string as it is a number or integer, and it needs to be typecasted because all the other parameters in the command line are integers.

You can also import the FloatText widget, which is the same as above but includes a floating-point slider. Wg.FloatText() is used.

Example #2

Code:

import numpy as np %matplotlib inline From matplotlib.pyplot as plt def myPlot (c): x = np.linspace(-5,5,20) y = c * x**2  # we are going to have a parabola here. plt.plot (x, y, ‘ r-- ‘) # let us make a plot using x and y values plt.ylabel (‘ y (x) ’) # create y label and make It y (x) plt.xlabel (‘ x ‘) # x label and named it x plt.ylim([ 0, 80 ]) plt.xlim ([ -5, 5 ])

myPlot(10) #running the plot with a random value.

Output:

But our point is to see the plot change with respect to c.

For that, we include a cSlider which sides along with the possible given values and updates the plot automatically. We can give a FloatSlider as well.

Code:

c_slide = wg.FloatSlider ( value = 1.0, min = 0.5, max = 3.5, steps = 0.2 ) #Then run the function by calling myPlot and include parameters to use. wg.interact (myPlot, c = c_slide)

Output:

c_slide.key: This is the keywords which display all the different types of widgets you might want to change. This will display quiet a big list.

wg.Widgets.widget_types: This is the keyword used to displays all the types of Widgets that can be used.

Example #3

Code:

import time progress = wg.IntProgress ( description = ‘ Loading: ’ ) progress.orientation = ‘horizontal’ #we can use vertical as well. display(progress) for i in range (100) progress.value = i time.sleep (0.1)

Output:

The loading bar in the above block of code can be taken as vertical, which shows a vertical orientation.

Try typing “import this” on Python IDE; you’ll find a poem highlighting the philosophies of Python.

Output:

Conclusion

Demonstration of many features of packages is done by importing Ipywidgets. Widgets can be styled and customised. They can be created using JavaScript and Python Notebook – Jupyter in this case. If you remove the keyword widget in case the same cell cannot be accessed, create subsequent command. Nevertheless, a widget can be created in another cell.

Recommended Articles

This is a guide to Python Widgets. Here we discuss the introduction to Python Widgets along with the examples, respectively. You may also have a look at the following articles to learn more –

Different Methods Of Tkinter Icon With Examples

Introduction to Tkinter Icon

Python encompasses various libraries that serve different purposes. Among them is Tkinter, a library employed in Python for constructing Graphical User Interfaces (GUIs). Tkinter is the easiest and fastest way to create Graphical User Interfaces in Python, and it also provides an object-oriented interface to the Tk GUI toolkit, which is very powerful. Tkinter icon is a way to put up our own customized icon on the different windows created by Tkinter. It is one of the most important parts of creating a Graphical User Interface. This article represents the different methods of the Tkinter icon and how it can be used in the different aspects of a GUI.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax:

Iconphoto() Method

iconphoto(self, default = False, *args)

Iconbitmap Method

call() Method

Methods of Tkinter Icon

Lets us discuss methods with Examples and their working:

 1. Iconphoto() Method

This method places a title bar icon on any top-level window. For setting up an image as the icon, the image needs to be an object of PhotoImage class.

Image used in example [i] & example [ii]-

Image used in example [iii]-

 [i] Basic Iconphoto() Usage Example

This is a basic example of creating a top-level window and putting up an image as its icon.

Code:

# Firstly import Tkinter Module from tkinter import * from chúng tôi import * import tkinter as tk # Then create a program Tkinter window program = Tk() # Photoimage class is created # And Image should be in the same folder where there is script saved p1 = PhotoImage(file = 'C:/Users/afu/Desktop/tk/Git.png') # Icon set for program window program.iconphoto(False, p1) # Button creation b = Button(program, text = 'Press Me!') b.pack(side = TOP) program.title('iconphoto() method') mainloop()

Output:

[ii] Advance Iconphoto() Usage Example

Code:

# Firstly import Tkinter Module from tkinter import * from chúng tôi import * from tkinter import Button import tkinter as tk # Then create a program Tkinter window program = Tk() # Photoimage class is created # And Image should be in the same folder where there is script saved p1 = PhotoImage(file = 'C:/Users/afu/Desktop/tk/Git.png') # Icon set for program window program.iconphoto(False, p1) # Button creation b = Button(program, text = 'Press Me!') b.pack(side = TOP) class Icon(Frame): def __init__(code): super().__init__() code.UI() def UI(code): framedesign = Frame(code, borderwidth=10) framedesign.pack() button1 = Button(framedesign, activebackground = 'SlateGray3', text='Change my color', bg = 'red') button1.pack(padx=5, side=LEFT) label1 = Label(framedesign, background='SlateGray3', width = 15) label1.pack(padx=5, side=LEFT) button2 = Button(framedesign, text='Mine too',background='blue', activebackground = 'SlateGray3') button2.pack(side=LEFT) label2 = Label(framedesign, background='SlateGray4',width = 15) label2.pack(side=LEFT) button3 = Button(framedesign, text='I am Green', background='crimson', activebackground = 'DarkSeaGreen3' ) button3.pack(side=RIGHT, padx=5) label3 = Label(framedesign, background='DarkSeaGreen3',width = 15) label3.pack(side=RIGHT, padx=5) button4 = Button(framedesign, text='Me too', background='pink',activebackground = 'DarkSeaGreen4') button4.pack(side=RIGHT) label4 = Label(framedesign, background='DarkSeaGreen4', width = 15) label4.pack(side=RIGHT) code.master.title("Advance iconphoto() method'") code.pack(fill=BOTH) code.pack() app = Icon() program.mainloop()

Output:

[iii] Advance Iconphoto() usage example with texts using multiple fonts

This example represents a way to create a window that sets up an image as its icon using an icon photo, and it also represents a way to set up different fonts in a window.

Code:

import tkinter as tk from tkinter import Tk from tkinter import BOTH from chúng tôi import Frame from chúng tôi import Label , Style from chúng tôi import Notebook program = tk.Tk() program.iconphoto(False, tk.PhotoImage(file='C:/Users/afu/Desktop/tk/Folder.png')) from chúng tôi import Font class Icon(Frame): def __init__(code): super().__init__() code.UI() def UI(code): code.master.title("program.iconphoto method example") code.pack(fill=BOTH, expand=True) text = "This example if for creating an icon " text1 = 'using program.iconphoto' text2 = 'Hope you like it' thefont = Font(family="Arial", size=16) label1 = Label(code, text=text, font=thefont) label1.grid(row=0, column=0) label2 = Label(code, text=text1, font="Times") label2.grid(row=1, column=0) label3 = Label(code, text=text2, font=('Courier', '18', 'bold')) label3.grid(row=2, column=0) app = Icon() program.mainloop()

 Output:

 2. Iconbitmap Method

For using this method, the bitmap image should be an icon type with .ico as its extension.

[i] Basic Iconbitmap Usage Example

This is a basic example of creating a window where the icon has been set using iconbitmap. As you can see, the image is of .ico extension, and using an icon-type image in this method is mandatory.

Code:

import tkinter as tk program = tk.Tk() program.title('iconbitmap method basic example') #Setting Icon for window widget program.iconbitmap('New.ico') program.mainloop()

Output:

[ii] Advance Iconbitmap Usage Example with Different Messages on pressing Buttons

This example shows us how to create a window with a bitmap image as its icon and buttons that display messages or ask questions when it is pressed. This example also explains how to make the window more responsive to questions and messages.

Code:

import tkinter as tk from tkinter import Frame, Tk from tkinter import Button from tkinter import LEFT, messagebox from tkinter import BOTH program = tk.Tk() program.iconbitmap('New.ico') #Setting Icon for window widget class Icon(Frame): def __init__(code): super().__init__() code.UI() def UI(code): framedesign = Frame(code, borderwidth=10) framedesign.pack() def Result(): tk.messagebox.showinfo( "Info", "Advance iconbitmap usage") def End(): MsgBox = tk.messagebox.askquestion ('End','Have you understood this program',icon = 'warning') if MsgBox == 'yes': program.destroy() else: tk.messagebox.showinfo('Return','Check our courses on Python on EduCBA') def Thanks(): tk.messagebox.showinfo( "Thanks", "Bbye, All the best for your future") button1 = tk.Button(framedesign, text='Know about me', command = Result, activebackground = 'Cyan') button1.pack(padx=5,side=LEFT) button2 = Button(framedesign, text='Question', width=8, command = End, activebackground = 'Cyan') button2.pack(padx=5, side=LEFT) button3 = Button(framedesign, text='Thanks', width=5, height=4, command = Thanks, activebackground = 'Cyan') button3.pack(side=LEFT) code.master.title("Advance iconbitmap usage Example with different text on buttons") code.pack(fill=BOTH) code.pack() app = Icon() program.mainloop()

 Output:

When Code is Executed

When “Thanks” Button is Pressed

Window

3. tk.call() Method

This method is an interface of Tkinter to the tcl interpreter. Image used in example [i] & example [ii]-

[i] Basic tk.call() Usage Example

This example represents the use of chúng tôi method.

Code:

import tkinter as tk program = tk.Tk() program.title('tk.call() method basic example') program.tk.call('wm', 'iconphoto', program._w, tk.PhotoImage(file='C:/Users/afu/Desktop/tk/dino.png')) program.mainloop()

Output:

 [ii] Advance tk.call() Usage Example

Code:

import tkinter as tk from tkinter import Tk from tkinter import Frame from tkinter import Label from tkinter import SUNKEN, LEFT from tkinter import FLAT, BOTH from tkinter import RIDGE, RAISED from tkinter import GROOVE program = tk.Tk() program.tk.call('wm', 'iconphoto', program._w, tk.PhotoImage(file='C:/Users/afu/Desktop/tk/dino.png')) class Icon(Frame): def __init__(code): super().__init__() code.UI() def UI(code): code.master.title("Advance tk.call() usage example") code.pack(fill=BOTH) framedesign = Frame(code, borderwidth=10) framedesign.pack() label1 = Label(framedesign, width=20, bg='#02FAFE', height=15, relief=GROOVE) label1.pack(padx=5, side=LEFT) label2 = Label(framedesign, bd=4, bg='#16DFE2', width=10,height=15, relief=GROOVE) label2.pack(padx = 5, side=LEFT) label3 = Label(framedesign, bd=4, bg='#28A6A8', width=20,height=15, relief=FLAT) label3.pack(padx=5,side=LEFT) label4 = Label(framedesign, bd=2, bg='#2A7778', width=10, height=15, relief=RAISED) label4.pack(padx = 5, side=LEFT) label5 = Label(framedesign, bd=3, bg='#173232', width=20, height=15, relief=RIDGE) label5.pack(padx=5,side=LEFT) code.pack() app = Icon() program.mainloop()

Output:

Conclusion

On the basis of the above example, an individual can understand how to set up images as a window’s icon. The different methods and examples describe the process of setting up images as an icon in different ways and also briefly introduce the different aspects of creating a GUI using Tkinter.

Recommended Articles

We hope that this EDUCBA information on “Tkinter Icon” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

Examples And Nested Begin & End Keyword Usage

Introduction to Begin SQL

Begin SQL is the keyword that is used to mark up and specify the beginning of the transaction or stored procedure or functions or simply the collection of multiple statements inside the logical block whose body starts from the specification of the BEGIN keyword and stops with the use of END keyword. We can write the sequence of the statement that we wish to execute inside the BEGIN and END keywords in SQL. Multiple BEGIN END statements can be written inside the same method or stored procedure, etc. We can even write nested BEGIN END statements in SQL where the logical block of statements defined between BEGIN and END keywords can be executed on a conditional basis or inside the loops and other functions according to the use case and requirement.

Start Your Free Data Science Course

In this article, we will learn about the syntax of using the BEGIN keyword in SQL and the END keyword that helps create a logical block of SQL statements with the help of syntax and few examples.

Syntax

The following is the syntax of using the BEGIN keyword in SQL, which is accompanied with END for termination of the block of statements –

BEGIN END

The use of BEGIN is mostly done in Transact-SQL, where multiple statements are executed completely in a transactional manner to maintain the consistency of the database operations and ACID properties of the database. We can mention the statements that we want to execute in a transactional manner inside the BEGIN and END keywords, as shown in the above syntax. The statements inside the BEGIN and END are also known as the batch that is executed together. We can mention the set of statements of SQL inside the BEGIN and END keywords.

Let us consider a few of the examples that will make the implementation of BEGIN in SQL clear to you.

Examples of Begin SQL

We will consider one existing table named students that are present inside the database named educba on my SQL server. The structure and contents of the table students can be seen from the output of the following query statement –

SELECT * FROM students;

The output of the execution of the above query statement is as follows –

The students’ table contains 14 records in it. Now, we want to execute three statements in the transact SQL that includes the addition of two records named Karna and Yudhishthira to the students’ table and, upon addition, retrieval of the records of the students’ table. We will place our SQL query statements of INSERT and SELECT queries inside the BEGIN and END keyword as shown in the below code –

BEGIN INSERT INTO `students` (`student_id`, `class_id`, `name`, `roll`, `technology`, `percentage`) VALUES('15','3','Karna','Manager','Maven','96%'); INSERT INTO `students` (`student_id`, `class_id`, `name`, `roll`, `technology`, `percentage`) VALUES('16','2','Yudhistir','Administrator','MySQL','92%'); SELECT * FROM students; END

The output of the execution of the above query statements and block is as follows –

We can observe that the two additional records have been inserted into the students’ table, and now, the students’ table contains 16 records in total that are retrieved from the third SELECT query that we mentioned in our logical block between BEGIN and END keywords.

Let us now consider one more example in which we want to get the records of the student’s names and id that have a percentage greater than 92, and if no records are retrieved, then it should give the output as ‘No students found that have achieved percentage greater than 92’. For this, we will first select the records from the student’s table that will have a percentage greater than 92 using the select query, and then if the row count of the retrieved query is zero, then we will select the string literal value that will contain the sentence as required when no such record is found.

We will use the IF statement to check the row count condition and will place all these statements inside the BEGIN and END to make them a single logical block that will consist of our statements as shown below –

BEGIN SELECT student_id, NAME FROM educba.students WHERE IF @@ROWCOUNT = 0 SELECT 'No students found that have achieved percentage greater than 92'; END

The output of the execution of the above query statements and block is as follows –

Nested BEGIN and END keyword usage

We can even make the use of nested BEGIN END blocks inside each other and create different logical blocks of statements to be executed. The BEGIN and END togetherly work as { and } in C, JAVA, or any other language. We can execute these logical blocks based on some conditions and also repetitively inside various looping statements of SQL.

Let us consider one simple example of nested BEGIN END blocks in SQL that will retrieve the name of the students that are ordered in the descending manner of their percentages and then get the value of the first record from the query that retrieves the names of students and stores the name of the student with the highest percentage inside the variable named @name. Further, we want to check if the row count of the result set of the query statement is not equal to zero, then print the value of the name in the string ‘The highest scoring student is the name of student else execute another block of BEGIN END that will get the string value ‘No student found’. We will use the following code for that –

BEGIN DECLARE @name VARCHAR(100); SELECT @name = NAME FROM educba.students ORDER BY percentage DESC; BEGIN SELECT 'The most highest scoring student is ' + @name; END ELSE BEGIN SELECT 'No student found'; END; END

The output of the execution of the above query statements and block is followed, retrieving the name of student Karna that has the highest percentage that is 96% –

Conclusion

We can make the use of the BEGIN keyword in SQL to mark the starting point of the logical block of statements of transact SQL that we need to specify and use the END keyword to specify the closing point of a logical block in SQL.

Recommended Articles

We hope that this EDUCBA information on “Begin SQL” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

Update the detailed information about Usage And Different Examples Of Sql Max() on the Bellydancehcm.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!