If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > SELECT with REPLACE!?!?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-14-04, 11:06
diegolaz diegolaz is offline
Registered User
 
Join Date: Feb 2004
Location: Argentina
Posts: 54
SELECT with REPLACE!?!?

Hi, I have 2 tables... in one, I have a filed that is a text type and I store a list of indexes from the other table (one per line).
TABLE A (fields: ..........., SECTORES,........)
TABLE B (fields: id_sector, name)
So when a make a query to, the field SECTORES has
"1
2
3
4"
But I want it to show the name that corresponds to that index. I can't doit via a join o WHERE because SECTORES its not a field with 1 value but a list of values...
I was trying to do it with REPLACE and SUBSTRING_INDEX..... but I can't figure it out ......
any ideas???
thanks!
Reply With Quote
  #2 (permalink)  
Old 08-15-04, 01:39
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
Change the structure of your database. Having a list of values in a field violates First Normal Form of database normalization.
Reply With Quote
  #3 (permalink)  
Old 08-15-04, 10:03
diegolaz diegolaz is offline
Registered User
 
Join Date: Feb 2004
Location: Argentina
Posts: 54
yes....... but

I was thinking on doind that.... but the problem is how do I represent the list? I can't add a field per each one because it's not a fixed number... maybe with only 1 field pointing to a table that represents the list?
thanks again.
Reply With Quote
  #4 (permalink)  
Old 08-15-04, 20:05
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
no, the A table does not point to the table that represents the list, the table that represents the list points to the A table --

create table TABLEA
( Aid integer not null primary key
, name varchar(55)
, ...
);
create table TABLEB
( id_sector integer not null primary key
, name varchar(55)
);
create table TABLEAB
( Aid integer not null
, id_sector integer not null
, primary key ( Aid, id_sector )
);
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 08-16-04, 08:51
diegolaz diegolaz is offline
Registered User
 
Join Date: Feb 2004
Location: Argentina
Posts: 54
yes!

Yes, I see how that could work, thanks very much for pointing that to me.
(I supose the third table is table C)
I let you know if it went alright.
Reply With Quote
  #6 (permalink)  
Old 08-16-04, 15:56
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by diegolaz
(I supose the third table is table C)
yes, i called it AB, to emphasize that it is a relationship table between A and B

you could also call it SECTORES

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On