954,560 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

help with query

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!

54uydf
Junior Poster
135 posts since Sep 2009
Reputation Points: 12
Solved Threads: 1
 

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.

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

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

54uydf
Junior Poster
135 posts since Sep 2009
Reputation Points: 12
Solved Threads: 1
 

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.

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: