MySQL Articles

Page 6 of 355

How to select last 10 rows from MySQL?

Chandu yadav
Chandu yadav
Updated on 12-Sep-2023 39K+ Views

To select last 10 rows from MySQL, we can use a subquery with SELECT statement and Limit concept. The following is an example. Creating a table. mysql> create table Last10RecordsDemo -> ( -> id int, -> name varchar(100) -> ); Query OK, 0 rows affected (0.75 sec) Inserting records into the table. mysql> insert into Last10RecordsDemo values(1, 'John'), (2, 'Carol'), (3, 'Bob'), (4, 'Sam'), (5, 'David'), (6, 'Taylor'); Query OK, 6 rows affected (0.12 sec) Records: 6 Duplicates: 0 Warnings: 0 mysql> insert into Last10RecordsDemo ...

Read More

How to cast from VARCHAR to INT in MySQL?

George John
George John
Updated on 07-Sep-2023 43K+ Views

To cast VARCHAR to INT, we can use the cast() function from MySQL. Here is the syntax of cast() function. cast(anyValue as dataType) For our example, we will create a table with the help of CREATE command. mysql> create table VarchartointDemo -> ( -> Value varchar(100) -> ); Query OK, 0 rows affected (0.51 sec) After creating a table, let us insert some records into the table with the help of INSERT command. The query is as follows − mysql> insert into VarchartointDemo values('123'); Query OK, 1 row affected (0.26 sec) ...

Read More

Best way to test if a row exists in a MySQL table

Ankith Reddy
Ankith Reddy
Updated on 06-Sep-2023 47K+ Views

To test whether a row exists in a MySQL table or not, use exists condition. The exists condition can be used with subquery. It returns true when row exists in the table, otherwise false is returned. True is represented in the form of 1 and false is represented as 0.For better understanding, firstly we will create a table with the help of CREATE command. The following is the query to create a table −mysql> CREATE table ExistsRowDemo -> ( -> ExistId int, -> Name varchar(100) -> ); Query OK, 0 rows affected (0.53 sec)After creating the table successfully, we will ...

Read More

Types of dependencies in DBMS

Amit Diwan
Amit Diwan
Updated on 06-Sep-2023 60K+ Views

Dependencies in DBMS is a relation between two or more attributes. It has the following types in DBMS −Functional DependencyFully-Functional DependencyTransitive DependencyMultivalued DependencyPartial DependencyLet us start with Functional Dependency −Functional DependencyIf the information stored in a table can uniquely determine another information in the same table, then it is called Functional Dependency. Consider it as an association between two attributes of the same relation.If P functionally determines Q, thenP -> QLet us see an example −EmpIDEmpNameEmpAgeE01Amit28E02Rohit31In the above table, EmpName is functionally dependent on EmpID because EmpName can take only one value for the given value of EmpID:EmpID -> EmpNameThe same is displayed ...

Read More

How to select first 10 elements from a MySQL database?

Chandu yadav
Chandu yadav
Updated on 06-Sep-2023 50K+ Views

To select first 10 elements from a database using SQL ORDER BY clause with LIMIT 10.The syntax is as followsSELECT *FROM yourTableName ORDER BY yourIdColumnName LIMIT 10;To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table Clients    - > (    - > Client_Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    - > ClientName varchar(20)    - > ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using INSERT command.The query is as followsmysql> insert into Clients(ClientName) values('Larry'); Query OK, 1 row affected (0.09 ...

Read More

Partial Dependency in DBMS

Alex Onsman
Alex Onsman
Updated on 06-Sep-2023 53K+ Views

What is Partial Dependency?Partial Dependency occurs when a non-prime attribute is functionally dependent on part of a candidate key.The 2nd Normal Form (2NF) eliminates the Partial Dependency.Let us see an example −ExampleStudentIDProjectNoStudentNameProjectNameS01199KatieGeo LocationS02120OllieCluster ExplorationIn the above table, we have partial dependency; let us see how −The prime key attributes are StudentID and ProjectNo, andStudentID =  Unique ID of the studentStudentName = Name of the studentProjectNo = Unique ID of the projectProjectName = Name of the projectAs stated, the non-prime attributes i.e. StudentName and ProjectName should be functionally dependent on part of a candidate key, to be Partial Dependent.The StudentName can be determined by StudentID, which makes the relation ...

Read More

How to select last row in MySQL?

Chandu yadav
Chandu yadav
Updated on 02-Sep-2023 61K+ Views

To select the last row, we can use ORDER BY clause with desc (descending) property and Limit 1. Let us first create a table and insert some records with the help of INSERT command. The query is as follows. mysql> create table getLastRecord -> ( -> Id int, -> Name varchar(100) -> ); Query OK, 0 rows affected (0.61 sec) After creating the above table, we will insert records with the help of INSERT command. mysql> insert into getLastRecord values(1, 'John'); Query OK, 1 row affected (0.13 sec) ...

Read More

How to get the datatype of MySQL table columns?

Anvi Jain
Anvi Jain
Updated on 02-Sep-2023 48K+ Views

You can get the MySQL table columns data type with the help of "information_schema.columns".The syntax is as follows −SELECT DATA_TYPE from INFORMATION_SCHEMA.COLUMNS where table_schema = 'yourDatabaseName' and table_name = 'yourTableName'To understand the above syntax, let us first create a table −mysql> create table DataTypeDemo −> (    −> Id int,    −> Address varchar(200),    −> Money decimal(10, 4) −> ); Query OK, 0 rows affected (0.60 sec)Apply the above syntax to get the MySQL columns data type. The query is as follows −mysql> select data_type from information_schema.columns where table_schema = 'business' and able_name = 'DataTypeDemo';The following is the output ...

Read More

Starting and Stopping MySQL Server

AmitDiwan
AmitDiwan
Updated on 02-Sep-2023 85K+ Views

Let us understand how MySQL server can be started and stopped on Linux and Windows −Linux – Start and Stop ServerOn Linux, the start and stop can be done from the command line as shown below −/etc/init.d/mysqld start /etc/init.d/mysqld stop/etc/init.d/mysqld restartLinux – Service CommandsSome Linux types offer service command as well −service mysqld startservice mysqld stop service mysqld restart(or)service mysql startservice mysql stopservice mysql restart Windows – Start and Stop ServerLet us understand how it can be done on Windows −Open 'Run' Window by using Win key + RType 'services.msc'Now search for MySQL service based on the version that ...

Read More

How to create a table with date column?

George John
George John
Updated on 02-Sep-2023 105K+ Views

To create a table with only date column, you can use DATE type. Let us first create a table −mysql> create table DemoTable    (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(20),    StudentAdmissionDate DATE    ); Query OK, 0 rows affected (0.47 sec)Insert records in the table using INSERT command −mysql> insert into DemoTable(StudentName, StudentAdmissionDate) values('Chris', now()); Query OK, 1 row affected, 1 warning (0.12 sec) mysql> insert into DemoTable(StudentName, StudentAdmissionDate) values('Robert', curdate()); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(StudentName, StudentAdmissionDate) values('David', '2019-05-21'); Query OK, 1 row affected (0.16 sec)Display all ...

Read More
Showing 51–60 of 3,543 articles
« Prev 1 4 5 6 7 8 355 Next »
Advertisements