bookmark.php Favorites Bookmark this page to Reddit Share this page on Twitter Bookmark this page to Delicious Bookmark this page to Facebook Bookmark this page to StumbleUpon More bookmarks

Shopping


Community




Discuss about databases and SQL related topics including MySQL, PostgreSQL, Oracle and SQL Server.
 March 29 2010

Basic SQL commands in phpMyAdmin: Search, Insert, Update, ..


kwok

Exclusive member

User Avatar


Reputation:
Medals: 1 
March 2010 (1)

 Joined: January 2010
 Country: United States (us)
 Location: WWW
 Posts: 144
Member Blog: View Blog (0)
Invitations sent: 0
Successful invitations: 0

F$: 2,465,871.00
Bank: 1,000.00
Instant Play Lottery Ticket Username - Black Post Count +100 Beer Gold Medal Silver Medal Gold Star Silver Star




In phpMyAdmin, open the SQL query window, and you can use one of these basic commands.
Search
Code: Select all
SELECT * FROM tablename WHERE fieldname < 30
(30 is only an example value)
This will search (SELECT) *(all columns) from the table WHERE the interested field is a number less than 30.

If you only wanted to see certain field, you can run this instead:
Code: Select all
SELECT field1 FROM tablename WHERE field2 < 30

This is helpful if your database contains a lot of fields that are irrelevant to what you are currently searching for.

Insert
If you know the exact order of the fields, use this:
Code: Select all
INSERT INTO tablename VALUES ( "value1a", "value1b", "value1c", "value1d" ), ( "value2a", "value2b", "value2c", "value2d"  )

If not, use this code:
Code: Select all
INSERT INTO tablename (field1, field2, field3, field4) VALUES ( "value1a", "value1b", "value1c", "value1d" ), ( "value2a", "value2b", "value2c", "value2d"  )


Find & Replace (Update)
Code: Select all
UPDATE tablename SET field2 = "value2", field3 = "value3", field 4 = "value4" WHERE field1 = "user1"

The important part of this command is WHERE, which insures that the information is only updated for "user1" and not for other users in the database.
For example:
Code: Select all
UPDATE `DBname`.`tablename` SET `fieldname` = '1' WHERE `fieldname` = '0'

Another example:
Code: Select all
UPDATE `tablename` SET fieldname1 = replace(fieldname1,"findthis","replacewith") WHERE `fieldname2` REGEXP '0';


Delete
Removing specific data by searching a condition from a query window or command line:
Code: Select all
DELETE FROM tablename WHERE fieldname < 30

If the entire table is no longer needed, you can remove it by clicking on the "Drop" tab in phpMyAdmin or running this command:
Code: Select all
DROP TABLE tablename
Last edited by kwok on April 27 2010, edited 3 times in total.
 

 April 26 2010

Delete duplicate entries wtih phpMyAdmin query


kwok

Exclusive member

User Avatar


Reputation:
Medals: 1 
March 2010 (1)

 Joined: January 2010
 Country: United States (us)
 Location: WWW
 Posts: 144
Member Blog: View Blog (0)
Invitations sent: 0
Successful invitations: 0

F$: 2,465,871.00
Bank: 1,000.00
Instant Play Lottery Ticket Username - Black Post Count +100 Beer Gold Medal Silver Medal Gold Star Silver Star




Code: Select all
delete from tablename where recordname in (select x.recordname from (select recordname from tablename group by recordname having count(*) > 1) as x)
 

 April 26 2010

Search MySQL table and DELETE the entries with certain value


kwok

Exclusive member

User Avatar


Reputation:
Medals: 1 
March 2010 (1)

 Joined: January 2010
 Country: United States (us)
 Location: WWW
 Posts: 144
Member Blog: View Blog (0)
Invitations sent: 0
Successful invitations: 0

F$: 2,465,871.00
Bank: 1,000.00
Instant Play Lottery Ticket Username - Black Post Count +100 Beer Gold Medal Silver Medal Gold Star Silver Star




Code: Select all
DELETE FROM tablename WHERE fieldname = value;
 

 April 26 2010

Copy a table from one database into another database


kwok

Exclusive member

User Avatar


Reputation:
Medals: 1 
March 2010 (1)

 Joined: January 2010
 Country: United States (us)
 Location: WWW
 Posts: 144
Member Blog: View Blog (0)
Invitations sent: 0
Successful invitations: 0

F$: 2,465,871.00
Bank: 1,000.00
Instant Play Lottery Ticket Username - Black Post Count +100 Beer Gold Medal Silver Medal Gold Star Silver Star




Code: Select all
INSERT INTO `intodb`.`tablename`
SELECT *
FROM `fromdb`.`tablename` ;


Find (all entries with certain value) and copy to another table
Code: Select all
INSERT INTO `intodb`.`tablename1` SELECT * FROM `fromdb`.`tablename1` WHERE `fieldname` =value;
Last edited by kwok on April 26 2010, edited 2 times in total.
 

 April 26 2010

Change MySQL Table Column Order (Move) with phpMyAdmin


kwok

Exclusive member

User Avatar


Reputation:
Medals: 1 
March 2010 (1)

 Joined: January 2010
 Country: United States (us)
 Location: WWW
 Posts: 144
Member Blog: View Blog (0)
Invitations sent: 0
Successful invitations: 0

F$: 2,465,871.00
Bank: 1,000.00
Instant Play Lottery Ticket Username - Black Post Count +100 Beer Gold Medal Silver Medal Gold Star Silver Star




+-------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------+------+-----+---------+-------+
| a | int(11) | YES | | NULL | |
| c | datetime | YES | | NULL | |
| b | varchar(3) | YES | | NULL | |
+-------+------------+------+-----+---------+-------+

Code: Select all
ALTER TABLE tablename MODIFY b VARCHAR(3) AFTER c


The result:
+-------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------+------+-----+---------+-------+
| a | int(11) | YES | | NULL | |
| b | varchar(3) | YES | | NULL | |
| c | datetime | YES | | NULL | |
+-------+------------+------+-----+---------+-------+
Last edited by kwok on April 26 2010, edited 2 times in total.
 

 April 27 2010

Insert a MySQL Table Column with phpMyAdmin


kwok

Exclusive member

User Avatar


Reputation:
Medals: 1 
March 2010 (1)

 Joined: January 2010
 Country: United States (us)
 Location: WWW
 Posts: 144
Member Blog: View Blog (0)
Invitations sent: 0
Successful invitations: 0

F$: 2,465,871.00
Bank: 1,000.00
Instant Play Lottery Ticket Username - Black Post Count +100 Beer Gold Medal Silver Medal Gold Star Silver Star




Insert 3 columns/fields to the end of the table:
Code: Select all
ALTER TABLE `tablename` 
ADD fieldname1 datetime NOT NULL default '0000-00-00 00:00:00',
ADD fieldname2 varchar(20) NOT NULL default 'open',
ADD fieldname3 bigint(20) NOT NULL default '0'


Insert column/field 2 after column/field 1:
Code: Select all
ALTER TABLE `tablename`  ADD `fieldname2` BIGINT(20) UNSIGNED NOT NULL AFTER `fieldname1`


Insert columns/fields 2 and 3 after column/field 1:
Code: Select all
ALTER TABLE `tablename`  ADD `fieldname2` DATETIME NOT NULL AFTER `fieldname1`,  ADD `fieldname3` DATETIME NOT NULL AFTER `fieldname2`
Last edited by kwok on April 27 2010, edited 2 times in total.
 

 April 28 2010

Rename Table name in PhpMyAdmin


kwok

Exclusive member

User Avatar


Reputation:
Medals: 1 
March 2010 (1)

 Joined: January 2010
 Country: United States (us)
 Location: WWW
 Posts: 144
Member Blog: View Blog (0)
Invitations sent: 0
Successful invitations: 0

F$: 2,465,871.00
Bank: 1,000.00
Instant Play Lottery Ticket Username - Black Post Count +100 Beer Gold Medal Silver Medal Gold Star Silver Star




Code: Select all
RENAME TABLE oldtablename TO newtablename


Alternatively, you can select the DB and click on the "Operations" link of the table. Under "Table Options", there should be "Rename table to." Enter the new name and click the "Go" button.
Last edited by kwok on April 29 2010, edited 2 times in total.
 

Related Threads

Last Post By


phpMyAdmin search and replace


  Started by kwok on March 28 2010
kwok
on March 28 2010 Go to last post
   Replies: 1    Views: 79

Copy a MySQL table with phpMyAdmin


  Started by kwok on March 29 2010
kwok
on March 29 2010 Go to last post
   Replies: 0    Views: 73
Display Options (This thread contains 7 posts) Currently Active Users Viewing This Thread
Posted Time Order By Sort By

No registered users and 1 guest

 
 Posting Rules

You cannot post new threads in this forum
You cannot reply to threads in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum





cron