www.webdeveloper.com
Results 1 to 2 of 2

Thread: How to Do: Value in Column Has to Exist in Another Table

  1. #1
    Join Date
    Jun 2006
    Location
    Under your bed
    Posts
    357

    How to Do: Value in Column Has to Exist in Another Table

    I have two tables. We'll call them table A and table B. They both have the column color_id. Is there any way I can tell MySQL to not add a row to table B if the color_id does not exist in table A?

  2. #2
    Join Date
    Sep 2011
    Posts
    60
    something like

    insert into B(color_id)
    select A.color_id
    from a
    left join B
    on a.color_id=b.color_id
    where b.color_id is null

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles