0

my table has 2 fields, both are Keys.
I save similar items in that table , like if 2 items are similar but have different Ids (in another table) I use this table to know that they are similar.

so if items 1111, 1112 are the same and 1000,1002,1004 are the same, it'll looks like this-
field1, field2
1111, 1112
1112, 1111
1000, 1002
1000, 1004
1002, 1000
1002, 1004
1004, 1002
1004, 1000

now I want to display the option to delete the connection between 2 items using a form, but I don't want the user to pick 1111,1112 AND 1112,1111 for removal, I want 1 connection to be displayed, and then I'll twist the vars and remove the other connection, but I don't know how to write a query that displays each connection only once!
help please!

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by pritaeas
0

One way would be to create a calculated column that concatenates both fields with the smallest first, so you can order and distinct that column.

Although that may work, I guess there has to be a better way.

0

I'm not sure what u meant but doing a simple DISTINCT on 1 culumn won't work since I'm going to get
1111,
1112,
1000,
1002,
1004.

and if I wanted to do a second query for each row to find it's conection then I'm going to get
1111-1112
and then for 1112 gonna get 1111, so I have the same connection twice..
:S

0

Something like:

SELECT field1, field2, IF(field1 < field2, CONCAT(field1, '-', field2), CONCAT(field2, '-', field1)) AS field3
FROM table
GROUP BY field3
ORDER BY field3

This may not work for you in all case, but it will give you the idea.

Edited by pritaeas: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.