9three Posted January 29, 2010 Share Posted January 29, 2010 Hi, I'm wondering if its possible to have 2 columns and have the data in them (integers) be unique to each other. Example: Column 1 - Column 2 1000 - 4522 Never again can that combination exist or 4522 - 1000 exist unless the row is deleted. Is this possible? Quote Link to comment https://forums.phpfreaks.com/topic/190188-unique-by-2-columns/ Share on other sites More sharing options...
premiso Posted January 29, 2010 Share Posted January 29, 2010 Sure, the way you would do it would be in the code and not in the DB. A simple query to check: SELECT id FROM table WHERE col1 = someint AND col2 = someint; If it exists then you do not insert it and re-generate a number, granted the more columns you have the potentially longer this process could take. Quote Link to comment https://forums.phpfreaks.com/topic/190188-unique-by-2-columns/#findComment-1003440 Share on other sites More sharing options...
9three Posted January 29, 2010 Author Share Posted January 29, 2010 Yea I already have something simliar to that I just thought there might be something like a UNIQUE Constraint but for two columns. thanks anyway Quote Link to comment https://forums.phpfreaks.com/topic/190188-unique-by-2-columns/#findComment-1003716 Share on other sites More sharing options...
premiso Posted January 29, 2010 Share Posted January 29, 2010 I do not know of any double unique constraints that would work in the way you describe. It will most likely have to be done on the code side (unless I am mistaken which I doubt I am). Quote Link to comment https://forums.phpfreaks.com/topic/190188-unique-by-2-columns/#findComment-1003745 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.