PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > Query
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Query

Réponse
 
LinkBack Outils de la discussion
Vieux 13/10/2007, 19h01   #1
JimJx
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Query

Hi everyone,

I am trying to write a query that joins 3 tables and having a
problem.... First, some structure info, the 3 tables are.....

Address
Name
Street
City
State
Zipcode
ID

Contact
Name
Phone
Fax
Email
URL

Keys
Name
Keywords
ID

Now, I get a term from a form and search Keys for matches in Keywords.

I take the Name value and go to the other tables for info based on
that name. For example to display all of the info for 'Antiques' I
use Keys to get the names of all of the antique dealers. I then need
go to Address and get the address info and Contact to get the contact
info.

I tried using
SELECT Cats.Name,Address.Address,Address.City
FROM Cats, Address
where Cats.Category LIKE '%%$search%%'

But that didn't work out. It gave me one name and well over 100
entries when I selected 'accountants' from the form when I know that
there are 6 accountants in the DB.

!

Thanks for reading,
Jim

  Réponse avec citation
Vieux 13/10/2007, 20h01   #2
Paul Lautman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Query

JimJx wrote:
> Hi everyone,
>
> I am trying to write a query that joins 3 tables and having a
> problem.... First, some structure info, the 3 tables are.....
>
> Address
> Name
> Street
> City
> State
> Zipcode
> ID
>
> Contact
> Name
> Phone
> Fax
> Email
> URL
>
> Keys
> Name
> Keywords
> ID
>
> Now, I get a term from a form and search Keys for matches in Keywords.
>
> I take the Name value and go to the other tables for info based on
> that name. For example to display all of the info for 'Antiques' I
> use Keys to get the names of all of the antique dealers. I then need
> go to Address and get the address info and Contact to get the contact
> info.
>
> I tried using
> SELECT Cats.Name,Address.Address,Address.City
> FROM Cats, Address
> where Cats.Category LIKE '%%$search%%'
>
> But that didn't work out. It gave me one name and well over 100
> entries when I selected 'accountants' from the form when I know that
> there are 6 accountants in the DB.
>
> !
>
> Thanks for reading,
> Jim


The first thing to say is that you should normalize the data. Your current
schema violates the first normal form and that is not good.

Also, in a case like this, Name should not be the foreign key. Two peoplecan
have the same name, yet do totally different things.

Next, you have used a comma join on the tables, but you haven't supplied any
join criteria. So it's not surprising that you got all the stuff out of the
address table.


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 00h54.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09514 seconds with 10 queries