Author Topic: very simple query  (Read 139 times)

0 Members and 1 Guest are viewing this topic.

Offline MikoTopic starter

  • Enthusiast
  • Gender: Male
    • View Profile
very simple query
« on: February 24, 2010, 11:20:02 AM »
Hi,

I'm trying to create a query that will get data from t1 and if not found go search in t2.

I have this for the moment:

Code: [Select]
SELECT * FROM tbl1, tbl2 WHERE tbl1.clnr = '$clnr' OR tbl2.clnr = '$clnr'
This kinda works but Instead of receiving 1 result I get the same result 100 times.

Anyone an idea? thanks :)
« Last Edit: February 24, 2010, 11:20:39 AM by Miko »

Offline fenway

  • MySQL Si-Fu / PHP Resident Alien
  • Global Moderator
  • 'Insane!'
  • *
  • Gender: Male
    • View Profile
Re: very simple query
« Reply #1 on: February 24, 2010, 02:50:11 PM »
You can't do that -- that' a cartesian product.

You need to JOIN the two tables, and then, depending on what's in that column, use COALESCE().
:anim_rules: Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

PHP Freaks Forums

« on: »

Tired of these ads? Purchase a supporter subscription to get rid of them.