Results 1 to 3 of 3

Thread: Joining tables

  1. #1
    Join Date
    Jan 2004
    Posts
    13

    Unanswered: Joining tables

    I have a bit of an issue that I can not seem to figure out and was hoping to get some feedback/advice from you all.

    First a little background. I have two databases and I am adding a new table too one of them. However I need to join the two databases but by columns and the columns I want to use to join them will use different data types and values.

    Example database 1 column 1 will be groups.group.id and database 2 column 1 will be users.group.id. However in database 2 (users) the group_id will contain different data.

    Database 1 group.id will contain a single integer and database 2 group.id I want to have it contain multiple integers seperated by a comma.

    Example code:
    select groups.group.id, groups.group.name
    from groups, users
    where groups.disabled='1'
    and users.user_id = $user_id
    and groups.group.id ? users.group.id

    The "?" is where I am having trouble. Does anyone know of a way to join two databases by columns using different data types?

    Thanks in advance for any input.
    Last edited by Toasted Onion; 02-12-04 at 12:20.

  2. #2
    Join Date
    Oct 2003
    Location
    Slovakia
    Posts
    482

    Re: Joining tables

    Originally posted by Toasted Onion
    I have a bit of an issue that I can not seem to figure out and was hoping to get some feedback/advice from you all.

    First a little background. I have two databases and I am adding a new table too one of them. However I need to join the two databases but by columns and the columns I want to use to join them will use different data types and values.

    Example database 1 column 1 will be groups.group.id and database 2 column 1 will be users.group.id. However in database 2 (users) the group_id will contain different data.

    Database 1 group.id will contain a single integer and database 2 group.id I want to have it contain multiple integers seperated by a comma.

    Example code:
    select groups.group.id, groups.group.name
    from groups, users
    where groups.disabled='1'
    and users.user_id = $user_id
    and groups.group.id ? users.group.id

    The "?" is where I am having trouble. Does anyone know of a way to join two databases by columns using different data types?

    Thanks in advance for any input.
    Some output errors? Post it here...

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002

    Re: Joining tables

    Originally posted by Toasted Onion
    ... and database 2 group.id I want to have it contain multiple integers seperated by a comma.
    there's your problem right there

    that is very poor design from the point of view of sql

    you will never get the join to work

    you have to retrieve the entire tables and do the join in your application code

    messy, eh?

    change your design and the sql join becomes trivially easy
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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