where-clause

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

别等时光非礼了梦想. 提交于 2019-11-26 08:05:50
问题 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

MySQL - ORDER BY values within IN()

别等时光非礼了梦想. 提交于 2019-11-26 07:00:15
问题 I\'m hoping to sort the items returned in the following query by the order they\'re entered into the IN() function . INPUT: SELECT id, name FROM mytable WHERE name IN (\'B\', \'A\', \'D\', \'E\', \'C\'); OUTPUT: | id | name | ^--------^---------^ | 5 | B | | 6 | B | | 1 | D | | 15 | E | | 17 | E | | 9 | C | | 18 | C | Any ideas? 回答1: SELECT id, name FROM mytable WHERE name IN ('B', 'A', 'D', 'E', 'C') ORDER BY FIELD(name, 'B', 'A', 'D', 'E', 'C') The FIELD function returns the position of the

Detect if value is number in MySQL

牧云@^-^@ 提交于 2019-11-26 06:51:59
Is there a way to detect if a value is a number in a MySQL query? Such as SELECT * FROM myTable WHERE isANumber(col1) = true This should work in most cases. SELECT * FROM myTable WHERE concat('',col1 * 1) = col1 It doesn't work for non-standard numbers like 1e4 1.2e5 123. (trailing decimal) T. Corner You can use Regular Expression too... it would be like: SELECT * FROM myTable WHERE col1 REGEXP '^[0-9]+$'; Reference: http://dev.mysql.com/doc/refman/5.1/en/regexp.html Dmitriy Kozmenko If your data is 'test', 'test0', 'test1111', '111test', '111' To select all records where the data is a simple

SQL server ignore case in a where expression

血红的双手。 提交于 2019-11-26 06:26:57
问题 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 回答1: 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 =

MySQL join with where clause

こ雲淡風輕ζ 提交于 2019-11-26 06:01:49
I have two tables I want to join. I want all of the categories in the categories table and also all of the categories subscribed to by a user in the category_subscriptions table. essentially this is my query so far: SELECT * FROM categories LEFT JOIN user_category_subscriptions ON user_category_subscriptions.category_id = categories.category_id This works fine however I want to add a where clause on the end of the query which then essentially makes it an inner/equi join. SELECT * FROM categories LEFT JOIN user_category_subscriptions ON user_category_subscriptions.category_id = categories

Left Join With Where Clause

允我心安 提交于 2019-11-26 04:06:47
问题 I need to retrieve all default settings from the settings table but also grab the character setting if exists for x character. But this query is only retrieving those settings where character is = 1, not the default settings if the user havent setted anyone. SELECT `settings`.*, `character_settings`.`value` FROM (`settings`) LEFT JOIN `character_settings` ON `character_settings`.`setting_id` = `settings`.`id` WHERE `character_settings`.`character_id` = \'1\' So i should need something like

WHERE vs HAVING

妖精的绣舞 提交于 2019-11-26 03:14:25
问题 Why do you need to place columns you create yourself (for example select 1 as \"number\" ) after HAVING and not WHERE in MySQL? And are there any downsides instead of doing WHERE 1 (writing the whole definition instead of a column name)? 回答1: Why is it that you need to place columns you create yourself (for example "select 1 as number") after HAVING and not WHERE in MySQL? WHERE is applied before GROUP BY , HAVING is applied after (and can filter on aggregates). In general, you can reference

“Or” equivalent in Linq Where() lambda expression

女生的网名这么多〃 提交于 2019-11-26 03:08:21
问题 Is there a method in Linq where you can use to build SQL strings like \"...where (a=1) OR (a=2)\"? 回答1: 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 ); }

Dynamic WHERE clause in LINQ

夙愿已清 提交于 2019-11-26 01:38:07
问题 What is the best way to assemble a dynamic WHERE clause to a LINQ statement? I have several dozen checkboxes on a form and am passing them back as: Dictionary<string, List<string>> (Dictionary<fieldName,List<values>>) to my LINQ query. public IOrderedQueryable<ProductDetail> GetProductList(string productGroupName, string productTypeName, Dictionary<string,List<string>> filterDictionary) { var q = from c in db.ProductDetail where c.ProductGroupName == productGroupName && c.ProductTypeName ==

MySQL join with where clause

时光怂恿深爱的人放手 提交于 2019-11-26 01:05:51
问题 I have two tables I want to join. I want all of the categories in the categories table and also all of the categories subscribed to by a user in the category_subscriptions table. essentially this is my query so far: SELECT * FROM categories LEFT JOIN user_category_subscriptions ON user_category_subscriptions.category_id = categories.category_id This works fine however I want to add a where clause on the end of the query which then essentially makes it an inner/equi join. SELECT * FROM