Page 1 of 1
Filtering?
Posted: Wed May 30, 2007 4:59 pm
by xterra
Hello,
Was wondering if you all wouldn't mind taking a look at something. This is my table:
[FK] [FK2]
1 1
2 1
3 1
1 2
2 2
3 2
Wellllllllll I would like to be able to select all where Fk2= 1 AND 2, but then i will have duplicates from the FK column. Can I make the results look like this?
1 1
2 1
3 1
I'm lost:(
Posted: Wed May 30, 2007 5:04 pm
by superdezign
Maybe try looking up the UNIQUE keyword (assuming you are using MySQL).
Posted: Wed May 30, 2007 5:25 pm
by xterra
superdezign wrote:Maybe try looking up the UNIQUE keyword (assuming you are using MySQL).
I took your advice and found the DISTINCT function. But, how can I run a query ON a query? So I select * from FK, and THEN run the distinct on the results???
Posted: Wed May 30, 2007 5:31 pm
by John Cartwright
Posted: Wed May 30, 2007 5:43 pm
by xterra
Right but how can I do that on a result from another query?
Filtering twice, I guess.
Posted: Wed May 30, 2007 5:49 pm
by RobertGonzalez
You're not running two queries. You are selecting DISTINCT, which means that the query will only return one value then move on.
PS | Moved to databases.
Posted: Wed May 30, 2007 5:55 pm
by xterra
Everah wrote:You're not running two queries. You are selecting DISTINCT, which means that the query will only return one value then move on.
PS | Moved to databases.
But when I put it into one query I am getting empty results.
select DISTINCT * from `applications` where `FK2` ='1' AND `FK2` = '2'
It *should* return at first this:
1
2
3
1
2
3
But then distinct should make it
1
2
3
Posted: Wed May 30, 2007 6:22 pm
by RobertGonzalez
Distinct will act on a field name.
Code: Select all
SELECT DISTINCT(`FK1`) FROM `applications` WHERE `FK2` <= 2;
Posted: Wed May 30, 2007 8:25 pm
by xterra
Everah wrote:Distinct will act on a field name.
Code: Select all
SELECT DISTINCT(`FK1`) FROM `applications` WHERE `FK2` <= 2;
I apologize, please bare with me I appreciate your help.
That would be fine but the last condition may be different. Is there a way I can change it where instead of WHERE `Fk2`<=2, could I make it something like:
WHERE `FK2` = '1' AND '2' AND '3' ?
Posted: Wed May 30, 2007 8:26 pm
by John Cartwright
Posted: Wed May 30, 2007 8:33 pm
by xterra
Wow. It works.
Thank you so much.
Posted: Wed May 30, 2007 8:33 pm
by xterra
And thank you as well Everah
Posted: Thu May 31, 2007 10:33 am
by RobertGonzalez
You're welcome.