Jump to content


Photo

How to delete DB entries based on LIKE clauses


  • Please log in to reply
3 replies to this topic

#1 Leburn

Leburn
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 19 September 2006 - 04:42 PM

Hey guys,

I have a minor problem here. I run a Hockey website where I use a script to parse the stats into the DB. Unfortunately, the Forward and Goaltender stats are stuck together. What I do currently is use 2 tables: 1 for Forwards and the other for Goaltenders, that's not the problem. My problem is my script parses the Forwards into the Goaltender table and vice versa. To combat this I have my script rename the position category to 'A'. By doing this, it allows me to use phpAdmin to use the search to find all entries with position 'A' and then delete the entries accordingly. I then remove duplicate entries afterwards based on the playername category.

 

Anyways my question is how can I create a script that uses a mysql query to do the following:

1. search table players for 'A' in category 'pos'
2. delete all entries (rows) that have 'A' in category 'pos'
3. delete duplicate entries based on category 'playername'

If someone can make me this script, I can then duplicate it for the goalie table myself.

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 20 September 2006 - 09:55 AM

1 & 2 -- DELETE * FROM yourTable WHERE pos ='A'
3 -- Not that I'm sure why you're getting duplicates, but you can use a unique index to prevent these records from being added in the first place.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 Leburn

Leburn
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 21 September 2006 - 09:32 AM

Well first I should tell you what my site is about.

It is a Fantasy based Hockey League using real players and teams (although we have contracted/added real teams). We use a text-based simulator called FHL Sim (Fantasy Hockey League Simulator) available @ www.fhlsim.com.

This sim is basically takes the life of a GM were you trade, draft, sign, release players. Your ultimate goal is obviously to win the Cup. Basically consider it the manager part of the EA Sports NHL series, but with 30 real GMs.

One of the nice features is the simulator outputs the statistics to html pages.

Now what I do is use a script to parse the data from these pages and place them into a DB. The script looks through the html source code to find the various stats.

I personally did not make the script from scratch, I was fortunate enough to have someone else send me a sample, which I then worked on for my league.
 
Now I think one of the duplicate issues is the fact that some players play for more than one team and therefore have 2 or more entries. The only issue here is for the current season stats, were all I care about is the latest entry for each player. However, I believe this issue will be resolved in our upcoming season as we will be doing the transactions differently.

Anyways, if you want to check out some examples of what I am talking about feel free to reply here, and I can post a few links to the stat pages, my parsing script, etc.

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 21 September 2006 - 01:25 PM

That doesn't change anything -- you'll have to decide which of the duplicates you want to keep.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users