- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 4219 Articles for MySQLi
560 Views
To select the last three rows in ascending order, use ORDER BY DESC LIMIT as in the below syntax −select * from (select * from yourTableName order by yourColumnName desc limit 3) anyAliasName order by yourColumnName ;Let us first create a table −mysql> create table DemoTable1579 -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(20) -> ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1579(Name) values('Robert'); Query OK, 1 row affected (0.37 sec) mysql> insert into DemoTable1579(Name) values('Bob'); Query OK, 1 ... Read More
294 Views
Here is the query to create first table.mysql> create table DemoTable1 -> ( -> StudentName varchar(20), -> StudentMarks int -> ); Query OK, 0 rows affected (0.67 sec)To understand the above concept, let us create second table.mysql> create table DemoTable2 -> ( -> Name varchar(20) -> ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2 values('Chris'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select * from DemoTable2;This will produce the following output −+-------+ ... Read More
139 Views
The easiest way to get number of rows, use aggregate function COUNT(*). Let us first create a table −mysql> create table DemoTable1575 -> ( -> FirstName varchar(20) -> ); Query OK, 0 rows affected (1.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1575 values('Chris'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1575 values('Bob'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1575 values('Adam'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1575 values('Robert'); Query OK, 1 row affected (0.15 sec)Display all records from the table ... Read More
788 Views
Let us first create a table −mysql> create table DemoTable1574 -> ( -> StudentCode varchar(20) -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1574 values('111_Carol'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1574 values('______'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable1574 values('David_12345'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1574 values('______'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select * from DemoTable1574;This will produce the following ... Read More
260 Views
To retrieve table names from a database in MySQL, the syntax is as follows −show tables from yourDatabaseName;Let us implement the above query in order to retrieve table names from a database in MySQL −mysql> show tables from hb_student_tracker;This will produce the following output −+------------------------------+ | Tables_in_hb_student_tracker | +------------------------------+ | demotable192 | | demotable193 | | demotable194 | | demotable195 | | demotable196 ... Read More
98 Views
Let us first create a table −mysql> create table DemoTable1572 -> ( -> StudentId int, -> StudentMarks int, -> StudentName varchar(20) -> ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1572 values(1, 79, 'Sam'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1572 values(2, 89, 'Chris'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1572 values(3, 98, 'David'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable1572 values(4, 79, 'Bob'); Query OK, 1 row affected (0.10 sec)Display all ... Read More
1K+ Views
To insert an IF statement into a MySQL query, use the below syntax::select yourColumnName ,if(yourCondition, yourStatement1, yourStatement2) from yourTableName;Let us first create a table −mysql> create table DemoTable1571 -> ( -> Id int, -> Value int -> ); Query OK, 0 rows affected (5.63 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1571 values(101, 500); Query OK, 1 row affected (1.07 sec) mysql> insert into DemoTable1571 values(102, 450); Query OK, 1 row affected (0.47 sec) mysql> insert into DemoTable1571 values(103, 300); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable1571 ... Read More
379 Views
You need to use port number 3306 in the URL. The syntax is as follows −jdbc:mysql://localhost:3306Exampleimport java.sql.Connection; import java.sql.DriverManager; public class MySQLConnectionToJava { public static void main(String[] args) { String JDBCURL="jdbc:mysql://localhost:3306/sample?useSSL=false"; Connection con=null; try { con = DriverManager.getConnection(JDBCURL,"root","123456"); if(con!=null) { System.out.println("MySQL connection is successful with port 3306."); } } catch(Exception e) { e.printStackTrace(); } } }OutputMySQL connection is successful with port 3306.
210 Views
Let us first create a table −mysql> create table DemoTable1570 -> ( -> ArrivalTime datetime -> ); Query OK, 0 rows affected (0.87 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1570 values('2019-10-15 5:10:00'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable1570 values('2019-10-15 23:00:00'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1570 values('2019-10-15 23:10:00'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1570 values('2019-10-15 16:10:00'); Query OK, 1 row affected (0.15 sec)Display all records from the table using select statement −mysql> select * from DemoTable1570;This ... Read More
2K+ Views
Let us first create a table −mysql> create table DemoTable1569 -> ( -> StudentId varchar(10), -> StudentName varchar(20) -> ); Query OK, 0 rows affected (3.05 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1569 values('John_12', 'John Smith'); Query OK, 1 row affected (0.38 sec) mysql> insert into DemoTable1569 values('David_321', 'Carol Taylor'); Query OK, 1 row affected (0.50 sec) mysql> insert into DemoTable1569 values('David_989', 'David Miller'); Query OK, 1 row affected (0.24 sec)Display all records from the table using select statement −mysql> select * from DemoTable1569;This will produce the following output+-----------+--------------+ | ... Read More