Trending December 2023 # How Url Works In Jdbc With Examples? # Suggested January 2024 # Top 15 Popular

You are reading the article How Url Works In Jdbc With Examples? updated in December 2023 on the website Daihoichemgio.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 January 2024 How Url Works In Jdbc With Examples?

Definition of JDBC URL

JDBC provides the URL to identify the database, so we can easily recognize the required driver and we can connect it. Basically JDBC URL we can use as database connection URL as per user requirement. When the driver loaded successfully we need to specify the required database connection URL to connect the database that the user wants. We know that the JDBC URL always starts with the JDBC keyword for the database connection; basically, the URL depends on the JDBC driver. We also need to provide the different parameters with the JDBC URL that is port number, hostname, database name, user name, and password, etc.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

specified protocol name//[specified host name][/specified database name][username and password]

Explanation

By using the above syntax, we try to implement the database connection, here we use different parameters such as protocol name, the hostname that we want, specified database name that we need to connect with the username and password, the database name depends on the user.

How URL works in JDBC?

Now let’s see how the URL works in JDBC as follows.

Register the JDBC Driver: After importing the class we need to load the JVM to fulfill that is it loaded the required driver as well as memory for JDBC request.

Database URL Formation: In this step, we need to provide the correct parameter to connect the specified database that we already discussed in the above point.

Create the Connection Object: After the formation of the URL, we need to create the object of connection that means we can call the DriverManager with grtConnection() methods to establish the connection with a specified database name.

Now let’s see in detail how we can import the JDBC Driver as follows.

Basically, the import statement is used to compile the java program and is also used to find the classes that are helpful to implement the source code as per user requirements. By using these standard packages, we can perform different operations such as insertion, delete and update as per user requirements.

import java.sql.*;

Now let’s see how we can register the JDBC Driver as follows.

We just need to import the driver before using it. Enlisting the driver is the cycle by which the Oracle driver’s class document is stacked into the memory, so it tends to be used as an execution of the JDBC interfaces.

You need to do this enrollment just a single time in your program. You can enlist a driver in one of two different ways.

The most widely recognized way to deal with registering a driver is to utilize Java’s Class.forName() technique, to progressively stack the driver’s class document into memory, which naturally enlists it. This technique is ideal since it permits you to make the driver enrollment configurable and compact.

2. By using DriverManager.registerDriver():

You should utilize the registerDriver() technique in case you are utilizing a non-JDK agreeable JVM, for example, the one given by Microsoft.

After you’ve stacked the driver, you can set up an association utilizing the DriverManager.getConnection() technique. JDBC provides the different JDBC drivers for the different database systems and we can utilize them as per the user requirement.

1. MySQL JDBC URL format:

This is the first JDBC URL format that can be used in MySQL to establish the connection with the required database name. The format of this URL is as follows.

(Connection con_obj = DriverManager.getConnection(specifed_jdbcUrl, user defined username, user defined password))

Explanation

In the above format, we use DriverManager.getConnection method to establish the connection with the database; here we need to pass the specified JDBC URL as well as we need to pass the username and password. The username and password fields are depending on the user. In JDBC URL we need to pass all parameters that we require to make the connection such as database name, protocol, etc.

2. Microsoft SQL Server URL format:

This is another famous URL format for the database system. Suppose we need to connect to the Microsoft SQL Server from a Java application at that time we can use the below-mentioned format as follows.

jdbc:sqlserver://[specified serverName[ specified instanceName][:required portNumber]][;property(that user defined properties)]

In the above syntax, we need to mention the server name that is the address of the server, or we can say that domain name or IP address. Also, we need to mention the instance name for server connection if we leave then it uses the default. In the same way, we can use port numbers and properties.

3. PostgreSQL JDBC URL format:

PostgreSQL is a famous open-source database system. So we can use the below-mentioned JDBC format as follows.

Jdbc:postgresql://hostname:port number/specified database name and properties. Examples

Now let’s see different examples of JDBC URLs for better understanding as follows.

import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.Statement; public class connection_t { public static void main(String args[]){ String m_url = " jdbc:mysql://localhost "; Connection con_obj = DriverManager.getConnection(m_url, "root", "root"); System.out.println("Connection successfully established with database. . ."); } }

Explanation

In the above example, we import the dependencies that are required to establish the connection with the database such as SQL. connection, SQL.DriverManger etc. After that, we import the class as shown. Here we also mentioned a connection string with connection parameters such as DriverManager.getConnection() method as shown. The final output or end result of the above example we illustrated by using the following screenshot as follows.

In the same way, we can connect to the Microsoft server and PostgreSQL as per our requirements.

Conclusion

We hope from this article you learn the JDBC URL. From the above article, we have learned the basic syntax of JDBC URLs as well we also see the different connection string URLs with different examples of JDBC URLs. From this article, we learned how and when we use the JDBC URL.

Recommended Articles

This is a guide to JDBC URL. Here we discuss the definition, syntax, How URL work in JDBC ? and examples respectively. You may also have a look at the following articles to learn more –

You're reading How Url Works In Jdbc With Examples?

How Dateadd Works In Redshift With Examples?

Introduction to Redshift dateadd

Redshift provides the different types of built-in functions to perform the different operations on the data as per user requirements. For example, the dateadd() is one of the functions provided by Redshift. Basically, the dateadd() function is used to return the new date-time values by adding the required date and timestamp, or we can say the specified date and timestamp as per user requirement. In other words, we can say the dateadd() function is used to return the specific date and time as per the interval that has been added. Normally the dateadd() function is used when we need to specify the future and past date and time as per requirement.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Explanation:

In the above syntax, we use dateadd() function with different parameters as follows:

specified datepart: The specified datepart means we can divide the data into different parts such as year, month, day, or we can say the hour, which means as per our requirement, we can divide the date.

specified interval: Interval means specified interval, or we can say the number of days that we required, either positive or negative. This is also depending on the user requirement.

How dateadd Works in Redshift?

Given below shows how dateadd() function works in Redshift:

Before execution of the dateadd () function, we need to be sure of the following point then we are able to perform the dateadd () function as follows:

First, we need to connect to the server that hosts the database that we want.

We must know the database name that we need to connect.

We also required the user name and password.

By utilizing window capacities, you can empower your clients to make insightful business inquiries all the more productively. Window capacities work on a segment or “window” of an outcome set and return an incentive for each column in that window. Conversely, no windowed capacities play out their computations as for each line in the outcome set. Dissimilar to bunch works that total outcome pushes, all columns in the table articulation are held. Normally the dateadd () function works on different parameters such as date and time. Again, we can divide the “date” into different parts: year, month, day, and time. We can divide it into the hours, second, millisecond, and microsecond as per user requirement. Suppose we need to specify the future date of our project; we can use the dateadd () function, add the interval, and add past date and time as per requirement.

Let’s see how we can date in various formats such as second, milliseconds, and microseconds as follows:

By using window limits, you can engage your customers to make shrewd business requests even more beneficially. Window limits work on a fragment or “window” of a result set and return a motivating force for every segment in that window. Then again, no windowed limits play out their calculations concerning each line in the result set. Unlike bundle works that complete result pushes, all segments in the table enunciation are held.

Examples of Redshift dateadd

Given below are the examples of Redshift dateadd:

Example #1

Let’s see how we can add the months into the current date as follows.

Code:

select dateadd(month,10,'2023-02-23');

In the above example, we use the dateadd function as shown; here, we need to add 10 months into the specified date, or we can say that literal value of date at that time we can use the above statement.

Here we use the default column name that date_add, as well as here use the default timestamp value that is 00. The final output of the above statement we illustrated by using the following screenshot as follows.

Output:

Example #2

Let’s see how we can add the timestamp into the date by using the dateadd() function as follows.

Code:

select dateadd(m,20,'2023-08-04');

Explanation:

In the above example, we use the dateadd() function as shown; suppose we need to add the timestamp into the specified date at that time, we can use the above statement.

In this example, we need to add the 20 minutes into the specified date by using the dateadd() function as shown in the above statement; similarly, we use the default column name the same as the above example. The final output of the above statement we illustrated by using the following screenshot as follows.

Output:

Example #3

Let’s see how we can use the dateadd() function in a different way as follows.

Code:

select dateadd(month,1,'2023-04-30');

Explanation:

In the above example, we use dateadd() function; suppose we need to add one month to the specified date at that time, we can use the above statement.

dateadd: If there are fewer days in the date you are adding to than in the outcome month, the outcome is the comparing day of the outcome month, not the last day of that month.

For instance, April 30 + multi-month is May 30. Similarly, here we use the default column name same as the above example. The final output of the above statement we illustrated by using the following screenshot as follows.

Output:

By using dateadd () function, we can also handle the leap year as per user requirements. So in this way, we can also implement the time, timetz, and timestamp with date function as per the user requirement.

Conclusion

From the above article, we have seen the basic concept as well as the syntax of Redshift dateadd() functions, and we also saw the different examples of the Redshift dateadd() function. From this article, we saw how and when we use the Redshift dateadd() function.

Recommended Articles

This is a guide to Redshift dateadd. Here we discuss the introduction, how dateadd works in Redshift? and examples, respectively. You may also have a look at the following articles to learn more –

How Serialization Works In Kotlin With Examples

Introduction to Kotlin Serialization

The kotlin serialization is the technique and process used to convert the application data with the specified format, and that can be transferred across the network, and it will be stored in the database or the external file. It may be any format like JSON, xml and it follows the protocol buffers. Here kotlin have the data serialization tools available in a separate component like “kotlinx.serialization” that package consists of the gradle plugins installed at the runtime libraries. The compile-time, type-safe mechanism for converting the objects into the data formats with a multi-platform supported environment.

Start Your Free Software Development Course

Syntax of Kotlin Serialization

The kotlin language has many default classes, methods, variables, and other keywords used to implement the mobile-based application. Serialization is the process of converting the object to the data stream, and it is used to store it as a separate file.

@Serializable data class className{ val name1: datatype val name2: datatype --------some declaration and logic codes--- } fun main() { ----Some main function codes depends on the above data class and the methods--- }

The above code is the basic syntax for creating and utilizing the serializable in kotlin language. We can use it anywhere on the programming codes, which depends on the requirement.

How does Serialization work in Kotlin?

Serialization is the process of converting the object data to the application data, and it can be stored with the separate file by using the format like json and xml etc. The kotlin has built-in functions, and it is completely used with the multi-platform supported used with the kotlin/native and kotlin/js. When we use non-kotlin type based file formats like json or xml based parser libraries would be suffered from some type of erasure data, and it could be the generic data type loses, so it should be avoided with the help of token type as the parameter in their serialization and deserialization functions.

We used other serialization techniques like polymorphic serialization, string customizability, framework integration and multi-format future types. Serialization is ignored and use the optional fields, and it can be used to adjust the default values, and it should be overridden for the JSON value format. In kotlin language, the new native standard serialization library was more similar to the java language concept like reflections used with the Android development. So the process of decomposing the inputs into the file stream for storing the datas that will be the encoded format. The encoder conversion is to be considered with another desired format for storing, processing and transforming datas into the other formats, which is on a similar requirement.

Examples of Kotlin Serialization

Given below are the examples of Kotlin Serialization:

Example #1

Code:

import kotlinx.serialization.Serializable import kotlinx.serialization.json.* import kotlinx.serialization.* import java.util.Base64 @Serializable class first(val n: String, @SerialName("lang") val lang: String) { fun demo() { val sn="Its the first string" ml.add("First Element is:Siva") ml.add("Second Element is :Raman") ml.add("Third Element is :Siva Raman") ml.add("Fourth Element is :Arun") ml.add("Fifth Element is :Kumar") println("Thank you users your first set of mutable list datas are:") for(vars in ml){ println(vars) } println("Thank you users your second set of mutable list datas are:") println(ml[2]) ml.add(2,"Sachin") println(" We can modify the first set mutable list ml.add(2,"Sachin")") for(vars in ml){ println(vars) } ml.add("Rajdurai") println("Again we can add the list values ml.add("Rajdurai")") for(vars in ml){ println(vars) } ml.addAll(1,mb) println("We can add all the list values to single list: ml.addAll(1,mb)") for(vars in ml){ println(vars) } ml.addAll(ma) println("We can add all the values and make it to the single list: ml.addAll(ma)") for(vars in ml){ println(vars) } ml.remove("Salman") println("We can remove the specified values: ml.remove("Salman")") for(vars in ml){ println(vars) } } } fun main() { val data = first("kotlinx.serialization", "Kotlin") var ref=first("Thank you for spenting the time with the serialization concept","Kotlin with Maven") var dt=ref.demo() var s= arrayOf(dt) for(ars in sequenceOf(s)) { println(ars) } var l= listOf(data) println(s) println(l) val str = "Welcome To My Domain its the first example that related to the kotlin serialization" val out: String = Base64.getEncoder().encodeToString(str.toByteArray()) println(out) }

Output:

The above example is the basic example that can be related to the @Serializable annotation, and it operates the class as serialized one, and it is operated in the main method to complete the operations.

Example #2

Code:

import kotlinx.serialization.* import kotlinx.serialization.* import java.util.Date import java.text.SimpleDateFormat @Serializable class Test() { var age: Int = 0 var name: String = "" var sex: String = "" fun demo2(){ val s="32,Siva, male" println(s) } } enum class Second(var sec: String) { demo("first method"){ override fun exam() { println("Java is the higher leve language") } }, demo1("second method"){ override fun exam() { println("C, C++ is the middle level language") } }, demo2("third method"){ override fun exam() { println("dotnet is the high level language") } }; abstract fun exam() fun demo1(stringValue: String): String{ return "Welcome" } } fun main() { val d = Test() var s=d.demo2() println(SimpleDateFormat("yyyy-MM-ddX").parse("2023-06-07+00")) println("Welcome To My Domain its the second example that relateded to the kotlin serialization, $s") }

Output:

Example #3

Code:

import kotlinx.serialization.Serializable import kotlinx.serialization.SerialName @Serializable @SerialName("Building") class Building(val structure: String){ var s1="Pyramid" var s2="V-Structure" var s3="Fire-Resistive" var s4="Hut" var s5="Wood frame" } @Serializable @SerialName("Types") fun main() { val res = "Welcome To My Domain its the third example that related to the kotlin serialization" println(res) var out=Building("Eiffel Tower") println(out) }

Output:

In the final example, we used @Serializable, and @SerialName are the two annotations that can be used to execute the serialized operations on both classes. Therefore, we created the two classes, and each class have assigned the SerialName annotation and Serializable.

Conclusion

In kotlin language, serialization is one of the concepts, and it is used to encode the datas so it’s encrypted the user inputs and using the de-serialization it can be decrypted. So it has different built-in methods, and it is used to perform the operation at the application level based on the requirement.

Recommended Articles

This is a guide to Kotlin Serialization. Here we discuss the introduction, syntax and working of serialization in kotlin along with different examples and code implementation. You may also have a look at the following articles to learn more –

How Parents() Function Works With Examples

Introduction to jQuery parents

Web development, programming languages, Software testing & others

Syntax:

$(selector ).parents(filter_expr)

Or

$(selector).parents()

In the above-given syntax, the jQuery parents() function is applied on a particular element. It is a selector tag where all ancestors are returned when this parent () function is applied to this selector tag. This function does not take any parameters, but still, it is considered optional.

selector: In this, the selector is nothing, but it is an HTML element or tag of which we want the element’s ancestors or grandparent element to be returned.

filter_expr: This is an optional parameter in this function for specifying the selector tag expression to look upwards in the DOM tree for searching with all this selector’s ancestors.

How parents() Function Works with Examples

In jQuery, the parents() function is a built-in function for displaying all the ancestors of the selected HTML tag for which this function needs to be applied. The working of this function is very simple Firstly, it will check for the specified selector tag, followed by the period (dot) operator and the parents() method to this selector tag. This function will traverse the entire DOM tree, where this tree is the representation of elements of the jQuery object.

Therefore parents() function traverses this DOM tree in the upward direction to search all the element’s ancestors such as grandparent element, great grandparent element, etc. are all displayed, which means this function parent () returns all the ancestor elements of the particular selected or matched HTML tag that is specified before the function declaration, and this particular specified selector optionally filters it. This function returns the element set in reverse order for the given multiple DOM having the original set, and the duplicate elements are removed and displayed.

Example #1

Code:

.parents_func_body* { display: block; border: 2px solid red; color: red; padding: 5px; margin: 15px; } <script $(document).ready(function() { $(“p”).parents().css({ “color”: “blue”, “border”: “2px solid red” }); });

Output:

In the above example, we have first made the document ready for the web page to be displayed according to the given function in the above code. In this, we are using the .ready() function for making the document ready. Then we specify the parents() function in which “p” the paragraph tag as a selector for this function, which means this function returns all the ancestor elements of the element “P” in the above code. Finally, we are applying the .css() function to properly display each element with described properties. This logic is defined or declared within the script tag, which is within the head tag.

Example #2

Now let us see another example for demonstrating the parents() function in which we are passing the optional parameters as some other HTML elements or selectors.

Code:

.main *{ border: 2px solid red; padding: 10px; margin: 10px; } function parents_func(){ $(document).ready(function(){ $(“p”).parents(“li, h2”).css({ “border”: “3px dashed blue”}); }); }

Conclusion – jQuery parents

In this article, we conclude that the parents() function in jQuery is very simple and is used to search or traverse the DOM tree, which consists of various elements to find out the parent element to help any developer to easily correct or upgrade any details. Similar to this parent () function, which returns all its ancestors elements of any selected element, even the parent() function also returns the direct parent element but not all the ancestors elements.

Recommended Articles

This is a guide to jQuery parents. Here we discuss the introduction and how parents() function works with examples, respectively. You may also have a look at the following articles to learn more –

How Stdin Works In Perl? With Examples And Advantages

Introduction to Perl STDIN

Syntax:

Below is the parameter description for the syntax as follows:

STDIN: STDIN is stands for standard input which we have used to take input from the user or to take from the keyboard or any input device. The STDIN will read the line entered from the keyboard along with the new line character and special character corresponding with the enter key which we have press after input.

Variable name: We have used any variable name to define STDIN in perl. We have used variable name to declare STDIN in perl. Variable name parameter is very important and useful in perl to declare value of STDIN variable. We have defined any name to the variable that we have used with STDIN in perl.

How STDIN works in Perl?

The STDIN will read the line entered from the keyboard along with the new line character and special character corresponding with the enter key which we have pressed after input.

STDIN stands for standard input which we have used to take input from the user or to take from the keyboard or any input device.

We can use it with the list context in perl. While using it with list of context it will take multiple value as input from the user.

After pressing enter it will identify that it would be individual elements in the list. We can press ctrl+D in Linux systems and ctrl+Z in windows system to indicate the end of the inputs.

It is very important and useful in perl to get standard input from console or take input from keyboard and any other input device.

It is used to get input from standard console by using it in perl. It is also called as standard input.

We can use it with the scalar context in perl. Scalar context is an operator in perl which have used with STDIN in perl.

Scalar context operator will read the line which was entered from the keyboard along with the new line character in perl.

Scalar context and list context operator is very useful and important. It is used to take input from the user by using STDIN.

We can declare it with variable name, also we can use any variable name to declare and initialize input.

We have defined any name of the variable that we have used with STDIN in perl. Variable name parameter is very important and useful in perl to declare value of STDIN variable.

Examples

Given below are the examples mentioned:

Example #1

STDIN in perl.

In below example we are getting data from the user using standard input.

Code:

use 5.030; use strict;      ## Use strict and warnings use warnings; say "Enter Name:"; say "Welcome $name_user in perl";

Output:

Example #2

STDIN using scalar context.

Below example shows a scalar context in perl. We are using scalar context operator. Scalar context operator will read the line which was entered from the keyboard along with the new line character in perl.

Code:

print "Enter age of usern"; # Getting age from the user by using age_user variable. # Removes new line from the input by using chomp in perl. chomp $age; print "Age is ", $age_user;

Output:

We have taken input as age from the user. We have removed new line character by using chomp. Chomp function removes the new line character from the code.

Example #3

Below example shows STDIN with a list context in perl. We are using list context operator.

Code:

# Get name from the user print "Enter name"; # Removes new line appended using chomp in perl. chomp @user_name; # Print the name of the user. print "nUser name is: [email protected]_name ";

Output:

Advantages

STDIN is used to take input from the user or any input device.

It is very useful and important in perl to take input from the keyboard or from the user.

We can get input from the standard console by using STDIN in perl.

We can take input of scalar and list context operator by using it.

Conclusion

STDIN stands for standard input and abbreviated the name as &lt;STDIN&gt;. The STDIN will read the line entered from the keyboard along with the new line character and special character corresponding with the enter key which we have pressed after input. It is very useful in perl.

Recommended Articles

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

Gude To How Does Mysql Alias Works With Examples

Introduction to MySQL Alias

MySQL Alias is used when we are willing to provide an alternate name for the column or table. Temporarily assigning a name for a column or table that is user-friendly and understandable. Alias is mainly used for the column and table. Column Alias gives an alternate name for the column headings, accessible for the end-user to understand. Table aliasing involves assigning alternate names to tables, which makes it more convenient to read and use them, particularly in the context of joins.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Syntax:

Given below is the syntax of the alias and how it is used in the column and table:

Here in the above syntax, we provide the column name which we want an alternate to be given. “AS” is optional. And at last, we provide the alias name.

Here in the above syntax, we provide the table name we want to give the alternate. “AS” is optional. And at last we provide the alias name.

How does MySQL Alias works?

MySQL Alias works in the following way:

1. Column Alias

Code:

CREATE TABLE EMPLOYEE_INFORMATION ( EMPLOYEE_ID VARCHAR(10), EMPLOYEE_NAME VARCHAR(20), DEPT_ID VARCHAR(10), EMPLOYEE_SAL INT );

Now let us insert data into the above table:

Code:

INSERT INTO EMPLOYEE_INFORMATION VALUES ('E1','SAM','D1', 90000); INSERT INTO EMPLOYEE_INFORMATION VALUES ('E2','WILL','D1', 80000); INSERT INTO EMPLOYEE_INFORMATION VALUES ('E3','SOMY','D1', 50000); INSERT INTO EMPLOYEE_INFORMATION VALUES ('E4','FRED','D1', 10000); INSERT INTO EMPLOYEE_INFORMATION VALUES ('E5','HARRY','D2', 70000); INSERT INTO EMPLOYEE_INFORMATION VALUES ('E6','PONY','D2', 70000); INSERT INTO EMPLOYEE_INFORMATION VALUES ('E7','DAVID','D2', 40000); INSERT INTO EMPLOYEE_INFORMATION VALUES ('E8','PETER','D3', 30000); INSERT INTO EMPLOYEE_INFORMATION VALUES ('E9','RAM','D3', 60000); INSERT INTO EMPLOYEE_INFORMATION VALUES ('E10','SAI','D3', 50000); select * from EMPLOYEE_INFORMATION;

Output:

Now let us give an alias to each column above without an underscore in the column name.

The below example is for the column aliasing:

Code:

SELECT EMPLOYEE_ID AS "EMPLOYEE ID", EMPLOYEE_NAME AS "EMPLOYEE NAME", DEPT_ID AS "DEPARTMENT_ID", EMPLOYEE_SAL AS "EMPLOYEE SALARY" FROM EMPLOYEE_INFORMATION;

Output:

2. Table Alias

A table alias is mainly used when we are performing joins on the table.

Below are the sample table with sample data to show how the alias is performed.

Code:

CREATE TABLE SAMPLE_A ( COL_A INT, COL_B INT );

Insert data into the table:

Code:

INSERT INTO SAMPLE_A VALUES (1, 5); INSERT INTO SAMPLE_A VALUES (2, 4); INSERT INTO SAMPLE_A VALUES (3, 3); INSERT INTO SAMPLE_A VALUES (4, 2); INSERT INTO SAMPLE_A VALUES (5, 1); select * from SAMPLE_A;

Output:

Now let us create another table.

Code:

CREATE TABLE SAMPLE_B ( COL_A INT, COL_B INT );

Insert data into the table:

Code:

INSERT INTO SAMPLE_B VALUES (1, 5); INSERT INTO SAMPLE_B VALUES (2, 4); INSERT INTO SAMPLE_B VALUES (3, 3); INSERT INTO SAMPLE_B VALUES (4, 2); INSERT INTO SAMPLE_B VALUES (5, 1); Select * from SAMPLE_B;

Output:

Now let us perform joining on above and use an alias:

a. Without Table alias

Code:

SELECT * FROM SAMPLE_A JOIN SAMPLE_B ON  SAMPLE_A.COL_A = SAMPLE_B.COL_A

Output:

b. With Table alias

Code:

SELECT * FROM SAMPLE_A A JOIN SAMPLE_B B ON A.COL_A = B.COL_A

Output:

Examples of MySQL Alias

Given below are the examples:

Example #1 – Column alias

Now let us find the maximum and minimum salary that each department has for the above table which we created earlier.

Code:

SELECT DEPT_ID AS "DEPARTMENT ID", MAX(EMPLOYEE_SAL)AS "MAXIMUM EMPLOYEE SALARY", MIN(EMPLOYEE_SAL)AS "MINIMUN EMPLOYEE SALARY" FROM EMPLOYEE_INFORMATION GROUP BY DEPT_ID;

Output:

Example #2 – Table alias

If we consider a table giving an alternate name for the table is said to be table aliasing.

Code:

SELECT * FROM SAMPLE_A JOIN SAMPLE_B ON SAMPLE_A.COL_A = SAMPLE_B.COL_A

Output:

Here every time mentioning the whole table name in the joining condition would be difficult.

b. With Table alias

Code:

SELECT * FROM SAMPLE_A A JOIN SAMPLE_B B ON A.COL_A = B.COL_A

Output:

Here every time mentioning the whole table name in the joining condition would be difficult. Hence, we have mentioned the alias for the table. SAMPLE_A has alias name as “A”. And SAMPLE_B table has “B” alias.

We could see that ‘AS’ is not written while mentioning the alias.

We can mention alias as below as well:

Code:

SELECT * FROM SAMPLE_A AS A JOIN SAMPLE_B AS B ON A.COL_A = B.COL_A

Output:

Conclusion

Things that need to put in mind regarding the MySQL Alias are if you want space to be provided in the alias_name, then we must enclose the alias_name in quotes. Spaces are accepted when we are defining in the column name. However, it is not good practice to use space in the table name aliasing. The alias_name is only valid within the scope of the SQL statement.

Recommended Articles

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

Update the detailed information about How Url Works In Jdbc With Examples? on the Daihoichemgio.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!