0o0o0 Posted October 4, 2008 Share Posted October 4, 2008 deleting all the info in a database... but leaving selected ones in ... ( repeated everyday) eg.. I used football say.. Delete * from NFL except where player = Brett Farve and player = Dan Marino is there a command like "except where" ??? anyone who can help would be awsome, ive applied to to many forums this week lol. thanks Quote Link to comment https://forums.phpfreaks.com/topic/126970-solved-a-problem-no-other-forum-has-answered-yet-can-you/ Share on other sites More sharing options...
F1Fan Posted October 4, 2008 Share Posted October 4, 2008 DELETE FROM table WHERE name != 'whatever' AND name != 'whatever' Quote Link to comment https://forums.phpfreaks.com/topic/126970-solved-a-problem-no-other-forum-has-answered-yet-can-you/#findComment-656795 Share on other sites More sharing options...
xtopolis Posted October 4, 2008 Share Posted October 4, 2008 even tastier: DELETE FROM table WHERE name NOT IN('Brett Farve','Dan Marino') Quote Link to comment https://forums.phpfreaks.com/topic/126970-solved-a-problem-no-other-forum-has-answered-yet-can-you/#findComment-656801 Share on other sites More sharing options...
F1Fan Posted October 4, 2008 Share Posted October 4, 2008 Downright YUMMY! Quote Link to comment https://forums.phpfreaks.com/topic/126970-solved-a-problem-no-other-forum-has-answered-yet-can-you/#findComment-656803 Share on other sites More sharing options...
0o0o0 Posted October 4, 2008 Author Share Posted October 4, 2008 lol guys are funny... thanks. Will these delete say all the other players rows and leave me with only marino and farves rows left in the db?? correct right? It'll be in a cron script so its doin this every day.. or if it were just once I would do it manually. (its not even a football db.. but using it to explain better what I wanna do. ) WHOA... now even a better question... importing from a cvs..file.. is there a possible way to rip only these two player for the csv before inserting into db? doubt it.. but thought Id ask. Quote Link to comment https://forums.phpfreaks.com/topic/126970-solved-a-problem-no-other-forum-has-answered-yet-can-you/#findComment-656805 Share on other sites More sharing options...
F1Fan Posted October 4, 2008 Share Posted October 4, 2008 Yup. Quote Link to comment https://forums.phpfreaks.com/topic/126970-solved-a-problem-no-other-forum-has-answered-yet-can-you/#findComment-656807 Share on other sites More sharing options...
0o0o0 Posted October 4, 2008 Author Share Posted October 4, 2008 lol this forum rocks you definately live up to the name.. I post a question and the answers there in mins! Freaks. how about this ... can you stop duplicates as they come into the db??? or only after by making a new temp table? thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/126970-solved-a-problem-no-other-forum-has-answered-yet-can-you/#findComment-656815 Share on other sites More sharing options...
F1Fan Posted October 4, 2008 Share Posted October 4, 2008 Well, you can run a select query before you insert, or you could add constraints on your DB table that won't allow that. Quote Link to comment https://forums.phpfreaks.com/topic/126970-solved-a-problem-no-other-forum-has-answered-yet-can-you/#findComment-656817 Share on other sites More sharing options...
0o0o0 Posted October 4, 2008 Author Share Posted October 4, 2008 k now im gettin peeved.. I went into sql console tester thing in myphpadmin and entered DELETE FROM MYTABLE WHERE player NOT IN('Farve') it ran it.. and succesfully did it.. so I wanted it to show me the exact php code and it gave me this... $sql = 'DELETE FROM MYTABLE WHERE player NOT IN(\'Farve\')'; so i throw that in my php code and run it from my php page.. refilled the db full of data again.. and tried it.. and it will not trim it down to farves.. ( again nfl just example) any idea? <?php include("../lalalalala.php"); $connection = mysql_connect($host,$user,$password) or die ("couldn't connect to server"); $db = mysql_select_db($database,$connection) or die ("Couldn't select database"); $sql = 'DELETE FROM MYTABLE WHERE player NOT IN(\'Farve\')'; mysql_close($connection); echo 'Test'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/126970-solved-a-problem-no-other-forum-has-answered-yet-can-you/#findComment-656862 Share on other sites More sharing options...
F1Fan Posted October 4, 2008 Share Posted October 4, 2008 I've never used single quotes around a query, and I think that may cause issues. Try this: $sql = "DELETE FROM MYTABLE WHERE player NOT IN('Farve')"; Quote Link to comment https://forums.phpfreaks.com/topic/126970-solved-a-problem-no-other-forum-has-answered-yet-can-you/#findComment-656865 Share on other sites More sharing options...
0o0o0 Posted October 4, 2008 Author Share Posted October 4, 2008 im lost... doesnt seem to want to work. but... it works in the sql tester console Quote Link to comment https://forums.phpfreaks.com/topic/126970-solved-a-problem-no-other-forum-has-answered-yet-can-you/#findComment-656872 Share on other sites More sharing options...
F1Fan Posted October 4, 2008 Share Posted October 4, 2008 I'm sorry, I'm really tired. You're never running the query. Add this: mysql_query($sql); after you declare $sql. Quote Link to comment https://forums.phpfreaks.com/topic/126970-solved-a-problem-no-other-forum-has-answered-yet-can-you/#findComment-656875 Share on other sites More sharing options...
0o0o0 Posted October 4, 2008 Author Share Posted October 4, 2008 omg.. your right.. ha ha ! me and you both... my eyes are so bloodshot.. ive been searchin for how to do this for 24+ hours straight. I can sleep now. Thanks alot Quote Link to comment https://forums.phpfreaks.com/topic/126970-solved-a-problem-no-other-forum-has-answered-yet-can-you/#findComment-656876 Share on other sites More sharing options...
0o0o0 Posted October 4, 2008 Author Share Posted October 4, 2008 ok I gotta ask one more question and im done for the weekend. how is it when loading a csv file into a db... it overwrites the info in the db? Id like it to just add to the end of whats already in the db. $sql = 'LOAD DATA LOCAL INFILE \'/home/sites/www.mywebsite.com/data/data.csv\' INTO TABLE `AUTO` FIELDS TERMINATED BY \',\' ENCLOSED BY \'"\' ESCAPED BY \'\\\\\' LINES TERMINATED BY \'\\r\\n\''; $result = mysql_query($sql) or die('Query failed: ' . mysql_error()); what am I missing or need to take out so the import will be added to the end of the db as the place to start loading. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/126970-solved-a-problem-no-other-forum-has-answered-yet-can-you/#findComment-656888 Share on other sites More sharing options...
F1Fan Posted October 5, 2008 Share Posted October 5, 2008 To be honest, I've never done an import from a csv to a sql db. Quote Link to comment https://forums.phpfreaks.com/topic/126970-solved-a-problem-no-other-forum-has-answered-yet-can-you/#findComment-657604 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.