Showing posts with label MySQL Language. Show all posts
Showing posts with label MySQL Language. Show all posts

Tuesday, January 27, 2015

[MySQL] How to know AUTO_INCREMENT value on some tables?

  Hi there~! Today we will study about mysql auto_increment value. When you create some tables that needs index number column, you will set auto_increment on that column. Yeah it's natural. Sometimes we need to know auto_increment value. Then after insert date, you call mysql_insert_id() function or like that. But if you need to know auto_increment value before inserting?

  If you want to know auto_increment value, you have to know this query.

SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = "databaseName" AND TABLE_NAME = "tableName"

[Execution query in phpmyadmin]


 In addition, you have only one database, you can use this query.
SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_NAME = "tableName"
[Execution query in phpmyadmin]



Did you get it? Go and Testing!

Wednesday, December 24, 2014

[Mysql] How to find duplicated value in table?



If you want to find duplicated value in table when you can not set unique for some column. Use this query.

Query 1. select column1,count(*) as count where my_table group by column1
* column1 is that you select, my_table is that you want to see.

Then you can see count column that you want to know what values are duplicated.

Query 2. select column1,count(*) as count where my_table group by column1 having count > 1

Then you can see all rows just be duplicated.