where-clause

In SQL / MySQL, what is the difference between “ON” and “WHERE” in a join statement?

无人久伴 提交于 2019-11-26 21:55:34
The following statements give the same result (one is using on , and the other using where ): mysql> select * from gifts INNER JOIN sentGifts ON gifts.giftID = sentGifts.giftID; mysql> select * from gifts INNER JOIN sentGifts WHERE gifts.giftID = sentGifts.giftID; I can only see in a case of a Left Outer Join finding the "unmatched" cases: (to find out the gifts that were never sent by anybody) mysql> select name from gifts LEFT OUTER JOIN sentgifts ON gifts.giftID = sentgifts.giftID WHERE sentgifts.giftID IS NULL; In this case, it is first using on , and then where . Does the on first do the

MySQL Multiple Where Clause

馋奶兔 提交于 2019-11-26 19:58:42
问题 I have a table like this: id image_id style_id style_value ----------------------------------- 1 45 24 red 1 45 25 big 1 47 26 small 1 45 27 round 1 49 28 rect I want to take image_id column if: style_id = 24 and style_value = red style_id = 25 and style_value = big style_id = 26 and style_value = round I have make a query like this: $query = mysql_query("SELECT image_id FROM list WHERE (style_id = 24 AND style_value = 'red') AND (style_id = 25 AND style_value = 'big') AND (style_id = 27 AND

SQL server ignore case in a where expression

不羁的心 提交于 2019-11-26 19:44:29
How do I construct a SQL query (MS SQL Server) where the "where" clause is case-insensitive? SELECT * FROM myTable WHERE myField = 'sOmeVal' I want the results to come back ignoring the case In the default configuration of a SQL Server database, string comparisons are case-insensitive. If your database overrides this setting (through the use of an alternate collation), then you'll need to specify what sort of collation to use in your query. SELECT * FROM myTable WHERE myField = 'sOmeVal' COLLATE SQL_Latin1_General_CP1_CI_AS Note that the collation I provided is just an example (though it will

Oracle date “Between” Query

本小妞迷上赌 提交于 2019-11-26 19:22:38
问题 I am using oracle database. i want to execute one query to check the data between two dates. NAME START_DATE ------------- ------------- Small Widget 15-JAN-10 04.25.32.000000 PM Product 1 17-JAN-10 04.31.32.000000 PM select * from <TABLENAME> where start_date BETWEEN '15-JAN-10' AND '17-JAN-10' But I dont get any results from above query. I think I have to use "like" and "%". But I dont know where to use them. Please throw some lights on this. thanks in advance. 回答1: Judging from your output

How to write a SQL DELETE statement with a SELECT statement in the WHERE clause?

末鹿安然 提交于 2019-11-26 15:48:45
问题 Database: Sybase Advantage 11 On my quest to normalize data, I am trying to delete the results I get from this SELECT statement: SELECT tableA.entitynum FROM tableA q INNER JOIN tableB u on (u.qlabel = q.entityrole AND u.fieldnum = q.fieldnum) WHERE (LENGTH(q.memotext) NOT IN (8,9,10) OR q.memotext NOT LIKE '%/%/%') AND (u.FldFormat = 'Date') ; This is the DELETE statement I have come up with: DELETE FROM tableA WHERE (SELECT q.entitynum FROM tableA q INNER JOIN tableB u on (u.qlabel = q

In Haskell, when do we use in with let?

扶醉桌前 提交于 2019-11-26 15:16:32
问题 In the following code, the last phrase I can put an in in front. Will it change anything? Another question: If I decide to put in in front of the last phrase, do I need to indent it? I tried without indenting and hugs complains Last generator in do {...} must be an expression import Data.Char groupsOf _ [] = [] groupsOf n xs = take n xs : groupsOf n ( tail xs ) problem_8 x = maximum . map product . groupsOf 5 $ x main = do t <- readFile "p8.log" let digits = map digitToInt $concat $ lines t

“Or” equivalent in Linq Where() lambda expression

*爱你&永不变心* 提交于 2019-11-26 14:16:49
Is there a method in Linq where you can use to build SQL strings like "...where (a=1) OR (a=2)"? You can certainly do it within a Where clause (extension method). If you need to build a complex query dynamically, though, you can use a PredicateBuilder . var query = collection.Where( c => c.A == 1 || c.B == 2 ); Or using a PredicateBuilder var predicate = PredicateBuilder.False<Foo>(); predicate = predicate.Or( f => f.A == 1 ); if (allowB) { predicate = predicate.Or( f => f.B == 1 ); } var query = collection.Where( predicate ); You can use the standard .NET boolean operators in your single

How to add a where clause in a MySQL Insert statement?

戏子无情 提交于 2019-11-26 11:31:16
问题 This doesn\'t work: INSERT INTO users (username, password) VALUES (\"Jack\",\"123\") WHERE id=\'1\'; Any ideas how to narrow insertion to a particular row by id? 回答1: In an insert statement you wouldn't have an existing row to do a where claues on? You are inserting a new row, did you mean to do an update statment? update users set username='JACK' and password='123' WHERE id='1'; 回答2: A conditional insert for use typically in a MySQL script would be: insert into t1(col1,col2,col3,...) select

mySQL returns all rows when field=0

断了今生、忘了曾经 提交于 2019-11-26 11:18:33
问题 I was making some tests, and it was a surprise when i was querying a table, and the query SELECT * FROM table WHERE email=0 returned all rows from the table. This table has no \'0\' values and it\'s populated with regular e-mails. Why this happens? This can lead to serious security problems. Is there a way to avoid this without modifying the query? Am i missing something here? Thanks. 回答1: This is because it is converting the email field (which I assume is a varchar field) to an integer. Any

What&#39;s the difference between where clause and on clause when table left join?

核能气质少年 提交于 2019-11-26 09:45:14
问题 SQL1: select t1.f1,t2.f2 from t1 left join t2 on t1.f1 = t2.f2 and t1.f2=1 and t1.f3=0 SQL2: select t1.f1,t2.f2 from t1 left join t2 on t1.f1 = t2.f2 where t1.f2=1 and t1.f3=0 The difference is where and on clause, is there same return result? and what\'s the difference ? does DBMS run them in same way? thanks. 回答1: The where clause applies to the whole resultset; the on clause only applies to the join in question. In the example supplied, all of the additional conditions related to fields on