5 Replies - 1888 Views - Last Post: 13 October 2006 - 07:35 AM Rate Topic: -----

#1 matt-the-mash  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 122
  • Joined: 10-July 06

Checking 2 tables for a value

Posted 08 August 2006 - 07:51 AM

Hi,

Can anybody help?

I need to check to see if a single value exists within either of my 2 tables on a database. I've looked at union and join but cant get it to work?
Is This A Good Question/Topic? 0
  • +

Replies To: Checking 2 tables for a value

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Checking 2 tables for a value

Posted 08 August 2006 - 12:08 PM

A join looks (primarily) for the same value within both tables. Can I assume this is a situation in which you have table1 with a field of field1, and table2 with a field of field2, and you want to check both tables to see if valueX is in table1.field1 OR table2.field2?
Was This Post Helpful? 0
  • +
  • -

#3 matt-the-mash  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 122
  • Joined: 10-July 06

Re: Checking 2 tables for a value

Posted 08 August 2006 - 01:03 PM

Hi Amadeus, i thought there was no one out there in the abyss!!!

Im not sure if ive gone about solving my problem the right way, but it seemed the most logical way to create two tables and then check against the pair.

The two tables contain identical field names. I will enter the customer detais into a table depending on which choice they make on my booking form.

Lets say we have room1 and room2, If a customer selects room1 , then i will put their detail into table room1.

If they book again later, i want to be able to check the database, if their detail exists in either room1 or room2.

I think this is what you are suggesting, but i tried a running a 'join' query earlier and got a mysql_num_rows() not valid etc. etc. error.

Do i need to alter the result synatx?

I think i wrote the syntax correct for the 'join' query.

If you think you can help, and you need more info, i will post my query tomorrow.

Cheers :D
Was This Post Helpful? 0
  • +
  • -

#4 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Checking 2 tables for a value

Posted 08 August 2006 - 02:19 PM

You certainly can post the query, but I'd like to suggest that you keep all the information in one table, and that table can hold the user information and a new column called room, in which you can store either room1 or room2, depending on the room they've booked.
Was This Post Helpful? 0
  • +
  • -

#5 matt-the-mash  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 122
  • Joined: 10-July 06

Re: Checking 2 tables for a value

Posted 09 August 2006 - 09:07 AM

Sorted, thanks!

Sometimes the simple answer just lies beneath all the confusion!!!!

I may have a couple of other questions soon.

I appreciate your help. :)
Was This Post Helpful? 0
  • +
  • -

#6 magscy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 25-September 06

Re: Checking 2 tables for a value

Posted 13 October 2006 - 07:35 AM

View PostAmadeus, on 8 Aug, 2006 - 12:08 PM, said:

A join looks (primarily) for the same value within both tables. Can I assume this is a situation in which you have table1 with a field of field1, and table2 with a field of field2, and you want to check both tables to see if valueX is in table1.field1 OR table2.field2?


hello, you can try this
set rs1 = table1
set rs2 = table2

select field1 from table1
do while not rs1.eof
select field2 from table2 where field2=rs1!field1
if rs2.recordcount <> 0 then print result
rs1.movenext
loop

Hope this will give you a little idea to solve your problem

View PostAmadeus, on 8 Aug, 2006 - 12:08 PM, said:

A join looks (primarily) for the same value within both tables. Can I assume this is a situation in which you have table1 with a field of field1, and table2 with a field of field2, and you want to check both tables to see if valueX is in table1.field1 OR table2.field2?


hello, you can try this
set rs1 = table1
set rs2 = table2

select field1 from table1
do while not rs1.eof
select field2 from table2 where field2=rs1!field1
if rs2.recordcount <> 0 then print result
rs1.movenext
loop

Hope this will give you a little idea to solve your problem
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1