Filtering?
Moderator: General Moderators
Filtering?
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:(
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:(
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
SELECT DISTINCT..Right but how can I do that on a result from another query?Jcart wrote:Code: Select all
SELECT DISTINCT..
Filtering twice, I guess.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
But when I put it into one query I am getting empty results.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.
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
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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.Everah wrote:Distinct will act on a field name.
Code: Select all
SELECT DISTINCT(`FK1`) FROM `applications` WHERE `FK2` <= 2;
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' ?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
.. WHERE `FK2` IN (1,2,3)- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA