where

Maximum values in wherein clause of mysql

Hi friends, Do anyone knows about how many values I can give in a where in clause? I get 25000 values in a where in clause and mysql is unable to execute. Any thoughts? Awaiting for your thoughts ...

MDX - Using "iif" function in the "Where" section

Hi I'd like to know how to make that "iif" work. Basically, I need to filter the engineering "product codes" when originator is "John Smith". currentmember is not working or that iif is not working, SELECT { ( [Time].[Fiscal Hierarchy Time Calculations].[Month to Date], [Measures].[Sell - Bookings] ) } ON C...

Alternative to 'where col in (list)' for MySQL

Hi I have the following table T: id 1 2 3 4 col a b a c I want to do a select that returns the id,col when group by(col) having count(col)>1 One way of doing it is SELECT id,col FROM T WHERE col IN (SELECT col FROM T GROUP BY(col) HAVING COUNT(col)>1); The intern select (from the right) returns 'a' and m...

MySQL: SELECT a Winner, returning their rank

Earlier I asked this question, which basically asked how to list 10 winners in a table with many winners, according to their points. This was answered. Now I'm looking to search for a given winner X in the table, and find out what position he is in, when the table is ordered by points. For example, if this is the table: Winners:...

SQL Problem, WHERE Statment is wrong

$sql = 'SELECT id, DATE_FORMAT(date,"%d.%m.%Y - %H.%i Uhr") AS dat, user1, user2, p_user1, p_user2, be_user1, be_user2, win FROM kok_1on1_matches WHERE user1="$user" OR user2="$user"'; What is wrong with the WHERE statement? ...

Mapping @OneToOne with @Where clause

I am trying to map an entity as following @OneToOne(mappedBy = "localizedLabel") @JoinColumn(insertable = false, updatable = false) @WhereJoinTable(clause = "locale='en_US'") public Localization getEn_US() { return en_US; } I can assure that the data will return only one or null if the not found, but hibernate seems to ignore my @...

Insert statement with where clause.

I had a table with unique Date_t1 date type field, but in Table description field is not mentioned as unique, now while inserting new row i need to validate if date exist or not, If already exist i should not allow to make changes on that row, neither a new row needs to be created, Any idea how to resolve this problem in efficient way, ...

SQL - Conditionally evaluate WHERE clauses

I need to get a WHERE clause to only evaluate certain statements. something like: WHERE field_a = field_b AND (CASE WHEN <PARAM>type</PARAM> = 5 THEN {field_c = 1 OR field_c = 2} WHEN <PARAM>type</PARAM> = 6 THEN {field_c = 3 OR field_c = 4} ELSE field_c = <PARAM>type</PARAM> so that when the Param type = 5...

Is it poor practice to build an SQL query using WHERE 1=1 AND ...

I'm writing a PHP script that builds an SQL query by concatenating the string and adding conditions to the WHERE clause as needed. Would it be better practice to use WHERE 1=1 so that the first condition is satisfied and the script can just concatenate an AND x = 'y' to the query, or should I write the extra code to check if a clause ha...

Is it possible to write a SQL query to return specific rows, but then join some columns of those rows with another table?

I'm having trouble wrapping my head around how to write this query. A hypothetical problem that is that same as the one I'm trying to solve: Say I have a table of apples. Each apple has numerous attributes, such as color_id, variety_id and the orchard_id they were picked from. The color_id, variety_id, and orchard_id all refer to thei...

unknown column in where clause

$result = mysql_query("SELECT * FROM Volunteers WHERE Volunteers.eventID = " . $var); $sql = mysql_query("SELECT * FROM Members WHERE Members.pid = " . $temp); I am also doing or die(mysql_error()) at the end of both statements if that matter. My problem is that the first statement executes perfectly but in that table I store an attri...

MySQL Query WHERE Including CASE or IF?

Strange problem. My Query looks like SELECT DISTINCT ID, `etcetc`, `if/elses over muliple joined tables` FROM table1 AS `t1` # some joins, eventually unrelated in that context WHERE # some standard where statements, they work/ CASE WHEN `t1`.`field` = "foo" THEN (`t1`.`anOtherField` != 123 AND `t1`.`anOtherField` != 456 A...

T-SQL Where statement - OR

Sorry for the vague title but I really didn't know what title to give to this problem: I have the following result set: ID Field FieldValue Culture 1 Color Groen nl-NL 2 Taste Kip nl-NL 3 Color Green en-GB 4 Taste Chicken en-GB 5 Color Green en 6 Taste Chicken ...

WHERE id IN doesn't work in UPDATE

UPDATE statistics' SET money = money + '$money' WHERE member_id IN ((SELECT member_id FROM races WHERE l_id = '$mem_id'), $other_id) What's wrong with that? I want to retrieve all member_ids from races and also include to member_id $other_id. Without $other_id it works. By the way, it gives me "Subquery returns more than 1 row" error....

MySQL where condition but not limited by it

Hello. I would like to run a query on my database like this: SELECT SUM( t1.value ) AS total1, SUM( t2.value ) AS total2, SUM( t3.value ) AS total3, SUM( t4.value ) AS total4 FROM pay1 t1, pay2 t2, pay3 t3, pay4 t4 WHERE t1.date = '2010-04-29' AND t2.date = '2010-04-29' AND t3.date = '2010-04-29' AND t4.date = '2010-04-29' I am genera...

MySQL: how to index an "OR" clause

I'm executing the following query SELECT COUNT(*) FROM table WHERE field1='value' AND (field2 >= 1000 OR field3 >= 2000) There is one index over field1 and another composited over field2&field3. I see MySQL always selects the field1 index and then makes a join using the other two fields which is quite bad because it needs to join 146...

mysql_query where statment help

I am retrieving values from the url with the GET method and then using a if statement to determine of they are there then query them against the database to only show those items that match them, i get an unknown error with your request. here is my code $province = $_GET['province']; $city = $_GET['city']; if(isset($province) && isset(...

Can SQL Server 2008 use a variable in a WHERE IN clause

Are there any updates in SQL 2008 to allow a variable for the IN of a where clause? Declare @InParams varchar(100) Set @InParams = '1,2' Select * from Category Where CategoryID in @InParams ...

postgres syntax question for OR?

The first one below works, but, just wanted to see if there's a better way... If I'm trying to find all records that start with 'C' with either a flag of 2 or a status of 9, do I need to incorporate the 'C' criteria twice? i.e., "SELECT * FROM mytable WHERE name like 'C%' AND flag = 2 OR name like 'C%' AND status = 9" Or, is ther...

Use of where in multiple joins to remove rows - linq

hi, I have a table of orders. the status is on the soilorders which is joined to the orders. I only want to return orders where the joined soilorder does not have status "Removed". I had thought that join sso in db.SoilSamplingOrders on ord.order_id equals sso.order_id where sso.status.Equals("Removed")!=true but then no re...