Forum Moderators: open

Message Too Old, No Replies

SELECT query using an array in the WHERE condition

"SELECT * tablename WHERE field='".$somearray."'"

         

uckc

10:07 pm on Mar 23, 2008 (gmt 0)

10+ Year Member



Hi all,

Here's a fictional representation of my tables:

Table1
ColumnA ¦¦ ColumnB
01 ¦¦ 23
01 ¦¦ 24
02 ¦¦ 30
03 ¦¦ 31
03 ¦¦ 32
03 ¦¦ 33
04 ¦¦ 34

Table2
ColumnA ¦¦ ColumnB ¦¦ ColumnC ¦¦ Column D
23 ¦¦ #*$! ¦¦ #*$!x ¦¦ #*$!x
24 ¦¦ #*$! ¦¦ #*$!x ¦¦ #*$!x
30 ¦¦ #*$! ¦¦ #*$!x ¦¦ #*$!x
31 ¦¦ #*$! ¦¦ #*$!x ¦¦ #*$!x
32 ¦¦ #*$! ¦¦ #*$!x ¦¦ #*$!x
33 ¦¦ #*$! ¦¦ #*$!x ¦¦ #*$!x
34 ¦¦ #*$! ¦¦ #*$!x ¦¦ #*$!x

Given that ColumnB on Table1 and ColumnA on Table2 are corresponding fields, I need to retrieve the rows on Table2, that have, for example, 03 as value on ColumnA on Table1.

Right now, I have the values of ColumnB on Table1, stored in an array, but I need to make another query to retrieve the rows from Table2, using the array as the WHERE condition. I tried using loops to set WHERE ColumnA='array[$num]', and $num auto-increments, tried putting the array name in the WHERE statement without the square brackets; I also looked on Google and in Books, but I just couldn't find the solution. Any help would be appreciated.

THANKS!

[edited by: eelixduppy at 10:28 pm (utc) on Mar. 23, 2008]
[edit reason] fixed spelling [/edit]

badone

8:56 am on Mar 24, 2008 (gmt 0)

10+ Year Member



Look at nested subqueries.