where-clause

Select from table1 WHERE table2 contains ALL search parameters

I have two tables (notes and tags). Tags has a foreign key to notes. There may be several tag records to a single note record. I'm trying to select only the notes that contain all of the desired tags. SELECT notes.*, tags.* FROM notes LEFT JOIN tags ON notes.id = tags.note_id WHERE {my note contains all three tags I would like to sear...

Linq To Sql 'Where Or' operator

I need to create a query which checks if a field (string) contains one or more words supplied at run time. Basically I need to be able to ask a WhereOr question. This seems like it should be a common issue when dealing with LinqToSql. I found the following reference but can't make sense out of it - and have no idea how to use it in my...

using the where clause + new constraint with args?

I have a piece of code that looks like this: public static T CreateSomething<T>(SomeType a) where T : SomeMicrosoftBaseClass, new() { var newElement = new T { SomeProperty = a}; DoStuff(); return newElement; } and now I need to change the code so I could pass to the constructor of SomeMicrosoftBaseClass a boolean argument ...

Example of Where cluase query including the MSACCESS database connection in C#

similar to title. just want an example of Oledb connection with Where clause query. ...

Converting conditionally built SQL where-clause into LINQ

So I didn't see a question here that really answers this question. It's kinda a newbie question about linq but I would like to know if it would be possible to convert the following sql query (built using C#) into a linq query: public void DoSomeQuery(bool whereCriteria1, bool whereCriteria2) { string sqlQuery = "SELECT p.*"; str...

Zend: How to use 'not equal to' in WHERE clause?

I am using following zend code to select all data from a table where verified=1 and it is working for me. $table = $this->getDbTable(); $select = $table->select(); $select->where('verified = 1'); $rows = $table->fetchAll($select); No I want to select all data from that table where verified is not equal to '1'. I have tried the followi...

Query with multiple wheres

I need to write a query that will perform a keyword search on a database table. The code currently looks something like this (albeit with a hard-coded set of keywords): var keywords = new [] { "alpha", "bravo", "charlie" }; IQueryable<Story> stories = DataContext.Stories; foreach( var keyword in keywords ) { stories = from story i...

How to have a query with columns needing different conditions in MySQL?

For a game, I want to count the number of user sign-ups by hour (using MySQL.). Quite easy, something like that: SELECT COUNT(*), DAY(date_user), HOUR(date_user) FROM users, GROUP BY DAY(date_user), HOUR(date_user) After that, I want to only take in consideration users which have played the game at least one time. I have a second t...

How to conditionally filter on a column in a WHERE clause?

OK, the umpteenth conditional column question: I'm writing a stored proc that takes an input parameter that's mapped to one of several flag columns. What's the best way to filter on the requested column? I'm currently on SQL2000, but about to move to SQL2008, so I'll take a contemporary solution if one's available. The table queried in...

using CASE in T-SQL in the where clause?

Im trying to use case to vary the value im checking in a where clause but I'm getting the error: incorrect syntax near the keyword 'CASE' SQL Server 2005 select * from table where ((CASE when adsl_order_id like '95037%' then select '000000'+substring(adsl_order_id,6,6) ELSE select adsl_order_id END) ...

How to specify a generic type should implement another generic type?

Imagine the following method public void SomeMethod<T>(T param) where T: List<T2> { } It doesn't work: Error 16 The type or namespace name 'T2' could not be found (are you missing a using directive or an assembly reference?) How do I achieve the what I clearly intended to do? ...

How can I prevent the LinqDataSource Where clause from resetting on postback?

I'm trying to set the where clause on a LinqDataSource object bound to a GridView programmatically on a button click, but when the GridView rebinds data (for instance, when the user sorts) the Where clause resets back to the empty string. Is there a way to prevent this, or is there a better way to filter my results? ...

How to use mySQL WHERE clause in PHP?

Can't seem to pass anything from the "securityinfo" field. for ($k = 1; $k < $fieldscnt; $k++) { $selectsecurityname = mysql_query("SELECT `security name` FROM securityinfo WHERE symbol = '$symbol[$k]'") or die(mysql_error()); $securityname = mysql_fetch_array($selectsecurityname); $sym = $symbol[$k] echo "<td>$sec...

MySQL Ordering Results by the order of Where Clause Matched

I have a query that tokenizes a phrase on spaces and needs to look for the best match for the phrase. It needs to return that match first. I'm trying to do this in a single query using where clauses. Is this possible? I'm trying something along these lines: for: my phrase select name from myTable where name="my phrase" or name like...

Where Clause Woes in Stored MySQL Query

What I'd like to do is execute a MySQL query containing a where clause ("result query") that is stored in a column in the database. This column, containing the query, is a result of another query ("original query"). The catches: The result query's where clause can contain a variable value (or two) I don't know what the result query ...

Combining LINQ statements for efficiency

Hi, regarding linq to objects, if i use a .Where(x => x....) and then straight afterwards use a .SkipWhile(x => x...) does this incur a performance penalty because i am going over the collection twice? Should i find a way to put everything in the Where clause or in the SkipWhile clause? ...

Query parent and child entries of one element in a single row

Hi there, I'm searching for the best way to display parent and child entries in one row. Example: Table A ID | PARENT_ID | VALUE ============================= 1 | | A 2 | 1 | B 3 | 2 | C 4 | | D 5 | 4 | E So I want to get the following result: ID ...

Conditional where clause in Mysql

How to use Conditional where clause in Mysql? Select * from table where SubId='1' and null Is it right? I want to display records with subId=1 and rows with subId null Any suggestion... ...

mysql where condition

Hi, I'm interested in where condition; if I write: Select * from table_name where insert_date > '2010-01-03' and text like '%friend%'; is it different from: Select * from table_name where text like '%friend%' and insert_date > '2010-01-03'; I mean if the table is very big, has a lot of rows and if mysql takes records complia...

dynamically varied number of conditions in the 'where' statement using LINQ

I'm working on my first project using LINQ (in mvc), so there is probably something very simple that I missed. However, a day of searching and experimenting has not turned up anything that works, hence the post. I'm trying to write a LINQ query (Linq to SQL) that will contain a multiple number of conditions in the where statement separa...