Scooby Posted January 26, 2012 Posted January 26, 2012 Hi, i have a small sql problem im not sure how to solve, ive been adding some property info to my sql table over time only to find ive been adding the info twice. (yes my bad ) my current layout is: x,y,z,type,dim,slot,rot,pPrice,oPrice,aPrice,forSale,owner,oldOwner,oldOwnerOwed,ID so currently it would look something like this (theres 1802 in total): 31,90,0,5,2000,9,214.7,99995,99995,0,No,Dave,None,0,1 31,90,0,5,2000,9,214.7,99995,99995,0,No,Dave,None,0,1 12,0,90,5,2001,1,122,24995,24995,0,Yes,Pete,None,0,2 12,0,90,5,2001,1,122,24995,24995,0,Yes,Pete,None,0,2 my question is, how would i go about removing one set of info but leaving the other there? i know the usual basic query's from the wiki but im not sure how i can do this without deleting both sets of info. [UVA]Scooby Founder Of UVA - Ultimate Vice Assassins http://www.uvaclan.com/
Jaysds1 Posted January 26, 2012 Posted January 26, 2012 I'm kinda confused, you want to remove 1 line of info and leave the rest of the info's. My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
Scooby Posted January 26, 2012 Author Posted January 26, 2012 well i have every line twice... so i was hoping somehow i could remove the duplicated lines. [UVA]Scooby Founder Of UVA - Ultimate Vice Assassins http://www.uvaclan.com/
NeXTreme Posted January 26, 2012 Posted January 26, 2012 So this is SQLite I guess? If you know which columns you have duplicate: executeSQLQuery("DELETE FROM tableName WHERE forSale='yes' AND owner='Dave' LIMIT 1") The "LIMIT 1" is the key here, it limits the query to affect only one row This is what I know from MySQL, I don't know if it will work with SQLite also, I don't use it. Website: http://www.twisted-gamers.net Don't you just love the error messages in LUA?
SDK Posted January 26, 2012 Posted January 26, 2012 Another way is using SELECT DISTINCT, which only selects unique rows and skips the duplicates, to create a (fixed) new db. "SELECT DISTINCT * INTO newtable FROM oldtable" Then drop (delete) the original table "DROP TABLE oldtable" and rename the new table to the old one. "ALTER TABLE newtable RENAME TO oldtable" (Found this after some googling, I'd expect it to work, but didn't test it so make sure you backup your database first) Learn Lua - Learn to script - GUI scripting Scripter tools - Find/fix errors yourself(!) Don't pm me for scripting help, keep it for the Scripting subforum!
Scooby Posted January 26, 2012 Author Posted January 26, 2012 thanks guys, this looks like what i need... i'll give it a try after work. everything i tried with the basic functions deleted both entries leaving the table blank so the 'limit' thing might be the key. but thanks both of u for taking the time out to help. Edit: ive tried both suggestions and had no luck with either... i get a syntax error for both LIMIT and INTO [UVA]Scooby Founder Of UVA - Ultimate Vice Assassins http://www.uvaclan.com/
SDK Posted January 27, 2012 Posted January 27, 2012 Yes, has been awhile since used sqlite im afraid The first query was wrong: "CREATE TABLE tempTable AS SELECT DISTINCT * FROM originalTable" "DROP TABLE originalTable" "ALTER TABLE tempTable RENAME TO originalTable" I tested it on a commandline and it worked, no duplicates. Learn Lua - Learn to script - GUI scripting Scripter tools - Find/fix errors yourself(!) Don't pm me for scripting help, keep it for the Scripting subforum!
Scooby Posted January 27, 2012 Author Posted January 27, 2012 heh no worries and thanks. ive just finished a workaround... looking at ur querys its a very long work around haha, but i think ive sorted it, i was bored so i wrote a small function to save each piece of data to an ID number in a table, then dropped the sql table and created it again, then resaved the old data from the new details stored. long way round i know but i got there in the end and if it happens again i'll be sure to remember these: "CREATE TABLE tempTable AS SELECT DISTINCT * FROM originalTable""DROP TABLE originalTable" "ALTER TABLE tempTable RENAME TO originalTable" thanks [UVA]Scooby Founder Of UVA - Ultimate Vice Assassins http://www.uvaclan.com/
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now