where

PHP MySQL Query Where x = $variable [closed]

╄→尐↘猪︶ㄣ 提交于 2019-12-17 16:07:32
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I have this code (I know that the email is defined) <?php $con=mysqli_connect($host,$user,$pass,$database); if (mysqli_connect_errno($con)) { echo

Rails “find_all_by” vs “.where”

*爱你&永不变心* 提交于 2019-12-17 16:04:21
问题 I have the following code: def maturities InfoItem.find_all_by_work_order(self.work_order).map(&:maturity) end I was thinking about changing it to: def maturities InfoItem.where(work_order: self.work_order).map(&:maturity) end Would there be any advantage to this? It seems like .where is more common than find_all_by nowadays. 回答1: My opinion is that using .where is a better approach. When you use attribute based finders, you are going to have to tunnel through a method missing call and

If condition in LINQ Where clause

╄→гoц情女王★ 提交于 2019-12-17 11:21:16
问题 Can I use if clause with Linq where? 回答1: Yes you can like: var query = someList.Where(a => a == "something"); if (condition) { query = query.Where(b => b == "something else"); } var result = query.ToList(); Because Where is producing an IQueryable , the execution is deferred until the ToList in my example so you can chain Where s together as much as you want and then just execute it after you have passed all your conditions. 回答2: var query = someList.Where(a => (someCondition)? a ==

Difference between “on .. and” and “on .. where” in SQL Left Join?

ⅰ亾dé卋堺 提交于 2019-12-17 10:44:47
问题 Sql statement. 1.select a.* from A a left join B b on a.id =b.id and a.id=2; 2.select a.* from A a left join B b on a.id =b.id where a.id=2; what is the difference of this two sql statement? 回答1: create table A(id int); create table B(id int); INSERT INTO A VALUES(1); INSERT INTO A VALUES(2); INSERT INTO A VALUES(3); INSERT INTO B VALUES(1); INSERT INTO B VALUES(2); INSERT INTO B VALUES(3); SELECT * FROM A; SELECT * FROM B; id ----------- 1 2 3 id ----------- 1 2 3 Filter on the JOIN to

SQL : BETWEEN vs <= and >=

折月煮酒 提交于 2019-12-17 03:28:09
问题 In SQL Server 2000 and 2005: what is the difference between these two WHERE clauses? which one I should use on which scenarios? Query 1: SELECT EventId, EventName FROM EventMaster WHERE EventDate BETWEEN '10/15/2009' AND '10/18/2009' Query 2: SELECT EventId, EventName FROM EventMaster WHERE EventDate >='10/15/2009' AND EventDate <='10/18/2009' (Edit: the second Eventdate was originally missing, so the query was syntactically wrong) 回答1: They are identical: BETWEEN is a shorthand for the

MySQL where clause and ordering by avg() as a sub query

Deadly 提交于 2019-12-14 02:18:47
问题 Although I can group and order by on an aliased sub query, I can't use the alias in a where clause. Do I need to use a join instead? Works: SELECT entries.*, (SELECT avg(value) FROM `ratings` WHERE ratings.entry_id = entries.id) as avg_rating FROM `entries` ORDER BY avg_rating DESC Fails ("unknown column 'avg_rating' in where clause"): SELECT entries.*, (SELECT avg(value) FROM `ratings` WHERE ratings.entry_id = entries.id) as avg_rating FROM `entries` WHERE avg_rating < '4.5000' ORDER BY avg

Linq where clause with multiple conditions

吃可爱长大的小学妹 提交于 2019-12-14 00:50:15
问题 this method returns generic list but it has multiple condition to get select. I'm just writing this using if - else if -else if.... so many if else i mean Is there a shorter way to do this? Thank you. public List<ProductReqNoDate> GetRequestsQuery(string departmant, int reqStateID, string firstDate, string lastDate) { var db = new requestsDBEntities(); var listPrn = new List<ProductReqNoDate>(); if (!string.IsNullOrEmpty(departmant)) { return (from r in db.requests where r.departmant==

MySQL - how to use wildcards in WHERE clause for the column names themselves? [closed]

寵の児 提交于 2019-12-13 22:50:29
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I've got a basic question about mysql. In my table 'table' I've got a column named 'foo' (String). And I'd like to do something like this: SELECT * FROM table WHERE %foo% LIKE '%thing%' But it's obviously

SQL Where ID equals ID but can be null

吃可爱长大的小学妹 提交于 2019-12-13 19:27:30
问题 I'm trying to fetch some data from an db. I've got an Taak table with an possible idPartij column. Possible, because it can be an real idPartij , but can also be null . The query I've got: SELECT T.idTaak, T.Taaktype, P.Partijnaam, T.Naar, T.UltimatumDatum, T.Opmerking, T.Status, T.Prioriteit FROM Taak AS T, Partij AS P WHERE T.idPartij = P.idPartij ORDER BY idTaak DESC This is working fine when I've got an id in T.idPartij , but as mentioned earlier, that id can be null . And when that is

Cross Join with Where clause

偶尔善良 提交于 2019-12-13 19:14:20
问题 In Linq i must create a query with method only, i've got 2 tables : Students (LastName, FirstName, Result) Grades (Max, Min, Name) I must select students ( LastName , FirstName ) and add to it the grade ( Result > Min && Result < Max ). In the end I must have : IEnumerable<T> T => LastName, FirstName, Grade I try this : var SAG = dc.Students .Where(w => w.Year_Result >= 12) .Join(dc.Grades, s => true, g => true, (s, g) => new { s.LastName, s.FirstName, Grade = g.Name .Where(w => (w.Min < s