Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,,plz help me.

SQL
SELECT *
FROM  `studentdetails`
WHERE Community =  'BC'
AND Department ='CSE'


This statement selects the rows which are have cse and bc in their department and community columns.
Simliarly i used this.

SQL
SELECT *
FROM  `studentdetails`
WHERE Community =  'BC'
AND Department ='CSE' AND Rank >100


I want to use the previous query for dynamic inputs. Please tel me how to get all community students above rank 100 belongs to CSE dept. I just want to know, which value i have to put for all community students in the place "Community= ".
Posted

1 solution

You don't. You remove the 'Community=' and just use the columns you want to filter on:
SQL
...WHERE Department = 'CSE' AND Rank > 100

This will let the database engine know not to use Community as a filter column.

If you are trying to make one query that will handle both queries above, then maybe you could try using LIKE statement:
SQL
... WHERE Community LIKE '%' AND Department = 'CSE' AND Rank > 100

This would only be reliable is your Community values were made up of distinctive character combinations, so that when specifying a community you would only get that one community, rather than all that match the character combination.

[EDIT]
I may not be understanding your question, so please explain it better if this does not answer what you are trying to ask.

You cannot use any wildcard characters in equality filters, meaning you cannot have the pattern ColumnName = '%', you can only use the wildcard characters with the LIKE construct for pattern matching when filtering results.

In order to include a particular column in the WHERE clause and not have it limit anything from your results, you need to use the pattern ColumnName LIKE '%'. This will match all entries in the column.
 
Share this answer
 
v4
Comments
suyambu123 26-Jul-11 18:53pm    
Thanks for your reply. I want to give dynamic inputs. Is there any way to mention all fields using the same structure. What i mean is, in mysql to allow direct connections from other than localhost we mention that '%' symbol to mention all hosts. Liskewise is there any symbol...? Plz help me
JOAT-MON 27-Jul-11 4:09am    
It sounds like you are asking about wildcard characters. Please see my edited answer above. Let me know if this is not what you are trying to ask about.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900