Be a Supporter!

mysql queries

  • 436 Views
  • 7 Replies
New Topic Respond to this Topic
JeremysFilms
JeremysFilms
  • Member since: Feb. 18, 2005
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
mysql queries 2006-11-13 19:14:44 Reply

if i want to delete all rows where the value is equal to a bunch of things, would i be able to do something like:
DELETE FROM tbl WHERE bob='hi' OR 'hello' OR 'hey'
is there any way to do something like that? or do i need to do a query for each?

Foxtrott
Foxtrott
  • Member since: Aug. 16, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to mysql queries 2006-11-13 19:23:23 Reply

You could do:
DELETE * FROM TABLE WHERE `thing`='something' AND `bla`='454'
and etc. You can use as many "AND" as you want.

DFox
DFox
  • Member since: Aug. 9, 2003
  • Offline.
Forum Stats
Member
Level 30
Blank Slate
Response to mysql queries 2006-11-13 19:28:31 Reply

I think it would need to look like:

DELETE FROM tbl WHERE bob='hi' OR bob='hello' OR bob='hey'

If you have too many and don't feel like doing that, just throw them in an array and have a loop tack them on to the SQL statement.


BBS Signature
henke37
henke37
  • Member since: Sep. 10, 2004
  • Offline.
Forum Stats
Member
Level 30
Blank Slate
Response to mysql queries 2006-11-14 02:49:33 Reply

There is a shorter form:
where a in ('a','b','c')

Much less typing


Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.

Rellizate
Rellizate
  • Member since: Feb. 27, 2006
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to mysql queries 2006-11-14 10:50:40 Reply

DELETE FROM `bob` WHERE `1` = '1' | `2` = '2';

Zendra
Zendra
  • Member since: Sep. 7, 2003
  • Offline.
Forum Stats
Member
Level 51
Blank Slate
Response to mysql queries 2006-11-14 10:54:11 Reply

At 11/14/06 10:50 AM, Rellizate wrote:

'1' | `2`

Something is wrong with that part.

Storm
Storm
  • Member since: May. 19, 2006
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to mysql queries 2006-11-14 11:12:59 Reply

At 11/14/06 10:50 AM, Rellizate wrote: DELETE FROM `bob` WHERE `1` = '1' | `2` = '2';

Isn't OR supposed to be || ?

Rellizate
Rellizate
  • Member since: Feb. 27, 2006
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to mysql queries 2006-11-14 14:35:52 Reply

My mistake:

DELETE FROM `bob` WHERE `1` = '1' || `2` = '2';