Database Query Problems

Results 1 to 3 of 3

Thread: Database Query Problems

  1. #1
    Join Date
    Dec 1969

    Default Database Query Problems

    Alright here is my current situation. I have two tables in my database one is named Phone_Cards and the other Countries. I have a field in Phone_Cards that is named Phone_Card_Countries and what that field does is allow the country id's to be entered in that are associated with the phone card. An example would be: 1, 4, 7. The problem is these have to be comma deliminted and after each comma represents a new country which has to be pulled from the country database. How do I set up the database query to go in a pick up country number 1 then 4 then 7. So this field allows multiple countries to be entered then each of them have to be pulled individually. Thank You In advance.

  2. #2
    Join Date
    Dec 1969

    Default Change the datamodel.

    You should never store comma separated values in a column.<BR>Put each value as a separate record. (You need an additional table.)

  3. #3
    Join Date
    Dec 1969

    Default What he said

    Usually a many to many structure requires a third "keys only" table...<BR><BR>Something like this...<BR><BR>tbl_PhoneCards<BR>--------------<BR>int_phoneCardID -- counter<BR><BR><BR>tbl_Card_Countries<BR>------------------<BR>int_PhoneCardID -- Numeric<BR>int_CountryCode -- Numeric<BR><BR>tbl_Countries<BR>-------------<BR>int_CountryID<BR><BR>When you associate a card with a country (or likewise)you need one entry in the card_Countries table.<BR><BR>Then you can select * from tblcards where int_cardid in (select int_cardid from tbl_card_countries where int_countrycode=12)<BR><BR>-- Whol

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts