Is Null Clause Takes A Lot Of Time But Is Not Null Statement Not
i have a query which takes 1 and half minute to fully execute. This query is following which return 2 records
select o.id, o.number, o.timest, o.receiptno, o.canedit, o.sessionid, o.voidorder, o.cashchange,p.amount from orders o left join payments p on (o.id=p.oid) where p.amount is null
but if i remove the 'not' from where clause then it takes a fraction of seconds. query is following which takes fraction of second and it returns 3920 records
select o.id, o.number, o.timest, o.receiptno, o.canedit, o.sessionid, o.voidorder, o.cashchange,p.amount from orders o left join payments p on (o.id=p.oid) where p.amount is not null
View Complete Forum Thread with Replies
Related Forum Messages:
Checking For Null In WHERE Clause
MySql 5.0.27 UPDATE USER SET USER.TITLE_ID=7 WHERE USER.TITLE_ID=NULL AND USER.DOMAIN_ID=2 AND USER.LAST_NAME='Jackson' The TITLE_ID filed for this user is indeed null. remove the USER.TITLE_ID=NULL then I can get the field to UPDATE to the given value. ie. UPDATE USER SET USER.TITLE_ID=7 WHERE USER.DOMAIN_ID=2 AND USER.LAST_NAME='Jackson'
View Replies !
IF NULL THEN Statement
the IF statement can't recognize a "NULL" in a column of INT? Code: FETCH c INTO x; # lets say the first x = NULL. IF x = NULL THEN ... END IF; That IF statement won't execute next when: x=1 Code: IF x = 1 THEN ... END IF; the If statement executes. What's up with that?
View Replies !
MySQL 4.0.17 Data Scrambles, Not-null Fields Become Null, Etc.
I'm having the most bizarre problem with PHP/MySQL that I've ever faced and it's an urgent matter (of course) to try to fix it ASAP. We have one record inserted into a table with 75 columns, whereby half of the columns are not-null, but for some bizarre reason, the fields are null. The rest of the columns that are null are completely scrambled (e.g. "first_name" is in "address2", "fax" is in "url", "url" is in "last_name", etc.) This just recently occurred and seems to have no history otherwise. It occurred sometime on Saturday when the record was inserted but logs indicate no unusual activity at that time. Has anyone seen this before and found a way to prevent it from occurring again?
View Replies !
Incorrect Integer Value: 'NULL' For Column Even If NULL Is Allowed
mysql> desc my_table; +------------+---------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+---------------------+------+-----+---------+-------+ | id | varchar(19) | NO | PRI | | | | value1 | int(11) | YES | | NULL | | | value2 | int(11) | YES | | NULL | | +------------+---------------------+------+-----+---------+-------+ I want to import data from a file that looks like this: 9bcd6f7b47a30fb8_01;NULL;NULL With following command: mysql> load data infile 'filename' into table my_table fields terminated by ';'; And get following error: ERROR 1366 (HY000): Incorrect integer value: 'NULL' for column value1'' at row 1 So the system denies me importing NULL values into a field where NULL is allowed.
View Replies !
Inserting Time As Null
I've really really really confused and really need your help please! I'm having trouble trying to insert data from a form into a mysql db, namely time. If a user only enters data for one day and leaves the other days of the week blank then it automatically defaults to 00:00:00. How do I tell it to default the insert to nothing, so that when I fetch the data and display it in a php echo it will only show the days with info. I hope I've explained that properly? Maybe I'm going about it the wrong way?
View Replies !
CASE Statement And NULL
I'm having trouble seeing what's wrong with the following case statement: CASE WHEN @Status='Active' THEN '1' WHEN @Status='Deleted' THEN '-1' ELSE '0' END @status = 'Active' is true and I've put in print statements to verify this, however the Status is always being set to 0. For some reason the case statement isn't recognizing the Status correctly so it thinks that @status is null
View Replies !
Getting Null Values From A TEXT NOT NULL Field
I have created a table with a field labeled Description which is a TEXT field which does not allow null values. It's defined with Description TEXT NOT NULL, However, when empty strings are stored in the Description field, I get NULLs back when querying the database. I'm writing an ASP application which connects to the MySQL database through ADODB. The MySQL version is 5.0.45. The engine is InnoDB.
View Replies !
CASE Statement Checking Null
I cannot figure out how to get a CASE statement to check a NULL field. I have: SELECT CASE transaction_id WHEN (transaction_id IS NULL) THEN 'out' ELSE 'in' END AS current_status FROM users_current_transaction WHERE user_id = 1 It is always returning 'in' even though the transaction_id for user_id 1 is NULL.
View Replies !
Is There A Way To Get A Negative Time Value To Display Rather Than Return NULL?
Quite new to MySql and thus far have been determined to learn everything by myself but I can't seem to find a resolution to this. Is there a way to get a negative time value to display rather than return NULL? i have calculated the sum of two columns seperately now want to subtract Sum(Column A) from SUM(Column B) - in some instances time value A is smaller than B this results in a negative which I want to see but the query returns NULL, I want the user to see that they are in negative numbers. here's my code: SELECT *, SEC_TO_TIME(TIME_TO_SEC(SEC_TO_TIME(SUM(TIME_to_SEC(phour)))-SEC_TO_TIME(SUM(TIME_to_SEC(mhour))))) AS Balance from toil.User join toil.toil on user.userid = toil.userid where name = 'X' FYI I'm working on a database to store details of Time Off In Leiu worked by staff
View Replies !
CREATE TABLE :: Null And Not Null
I recently created a new table in a database and wanted some fields to accept nulls (NULL) and others to not accept nulls (NOT NULL). The table was built correctly, however, when I went to edit a row in the Query Window of MySQL Browser it allowed me to enter in the row when the NOT NULL fields had no values attached to them - this should fail and stop me from entering a row. Here is the script for the table I created; CREATE TABLE SLG ( SLG_ID int(11) NOT NULL auto_increment, SLG_CODE CHAR(1) NOT NULL, SLG_DESCRIPTION VARCHAR(255) NOT NULL, SLG_DATE_CREATED DATETIME NOT NULL, SLG_DATE_MODIFIED DATETIME NOT NULL, PRIMARY KEY (SLG_ID) ); When I apply the changes in this window it just enters NULLS into all the other fields. Is this a Query Browser issue. I tried doing the same with an INSERT statement and received the same result. Also - related to creating a table - is it possible to create global Defaults on a database and then reference those in the DEFAULT statement of the CREATE TABLE command. MS SQL has a system function that can be executed after a table is created to bind a global default to a specific column.
View Replies !
Insert Null To Not Null Column
I have build a replication environment in my environment. the master is MySQL 5.0.24a-standard-log and the slave is 5.1.30-log. the configuration is not the same between them. I have found a replicaiton error in the slave today says: .....
View Replies !
NULL And NOT NULL Settings
I have a MySQL table that stores name and age of a person. The name field needs to have a value; the age field is optional.I'm quite confused now with the NULL and NOT NULL settings... It seems that neither one does what I want (rejecting an INSERT query where the name field is empty)...So what exactly do I have to do?
View Replies !
VARCHAR Null/Not Null
I'm having a problem with a table that is already created - I want insert attempts to FAIL when the column for 'firstname' is empty (a VARCHAR field). Currently, the column is set to Null=YES and a Default of 'NULL'. This allows records to be inserted with no 'firstname' value (NULL appears in the column). If I change it in phpmyadmin 'structure' to Null=NO and Default of [empty field] then it allows records to be inserted with no 'firstname', and 'firstname' shows empty in the column
View Replies !
PK Field Not Null Is Being Null
I m newbie. I made a MySQL database table and in the primary key field I set the data type VAR CHAR.I also set it not null .BUT still I can insert blank values in this PRIMARY KEY field. If I just blank my primary key field by this query- Insert Tablename Values ('','','','','',''); (if my table has 6 fields).HOW IS IT POSSIBLE. How can PK field allow blank value when I set not null. HOW TO SOLVE IT. 2. I use a MySQL GUI Tools from http://dev.mysql.com/downloads/. In Table viewer of Query browser, each time I insert the first field, it sets the datatype to INTEGER,NOT NULL, AUTO INCREMENT. But I change it to VARCHAR as needed. Do I have to/should use Integer type in PK field and can Varchar be incremented. 3.Can I set user privilege to a particular row (on a particular PK); HOW? 4. Is it correct/incorrect that the name of the foreign key has to be the same as the name of the corresponding PK. I saw that in MySQL I can easily change the FK name to anything else and then just make a reference of FK to the PK. 5. How can I make a one-to-one relationship in MySQL;
View Replies !
Setting Null To Not Null How?
i have a mysql table.. (duh!) a field in it is set to null and i want to unset it to make it not null. how do i do that ? by default it takes null values (its weird.. default is null while null column is a no.. so it cant take null values!)
View Replies !
Query Takes A Long Time
On my site I have a query that searches through 1,7 million. The php-file with the query takes a bit of time to load. Is it possible to show some sort of progress-bar during this time?
View Replies !
Results In Multiple Pages, Takes Too Much Time
I have a table of a million records and wrote a CGI-PERL script to display the results based on the user input. The results might be anywhere from 100 to 1000 per query and presently I am displaying them as 25 results per page. Problem: Each query is taking about 20-30 seconds. My solution: I have tried to optimize the table and also index the table. I have actually converted a MS access database to SQL database, so it wasn't previously indexed. Both optimization and indexing doesn't give any good results. I always get a timeout. ie. it takes longer after indexing and optimizing. 1. I was wondering if someone has a creative solution for this. ie. reduce the time from 20-30 seconds to atleast 10 seconds. 2. I have links of pages of results beneath the first page result. When each of these links are clicked it takes 20-30 seconds again. Is there a way I can reduce the time taken for the subsequent pages are reduced? I cannot use the LIMIT option in mysql, since I have a where clause which has to search through the whole table. I tried using views and using limits, but it takes as much time.
View Replies !
JDBC Result Closing Takes Time
i am reading 1000 Elements from a database (500.000 all together). The problem is reading the data takes only a few miliseconds but closing the ResultSet takes another 22 seconds. My Hard Disk tells me that the ResultSet is probably running to the end of my table row by row. Is there a way to tell mysql not to do this ? Statement tempStmnt = aConnection.createStatement(); tempStmnt = aConnection.createStatement( java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); tempStmnt.setFetchSize(Integer.MIN_VALUE); Date tempStart = new Date(); ResultSet tempRs = tempStmnt.executeQuery("SELECT * FROM ARTIKELSTAMMDATEN"); int tempXx = 0; while (tempRs.next() && tempXx++ < aCount) { tempRs.getString("artikelBezeichnung"); }
View Replies !
Easy SELECT With OR Takes A Very Long Time
We've got a database with about 1000000 books. A query in the table BOOKS for the TITLE 'java' is very fast. We have a fulltext index on the column TITLE. However, if we want to do a exact same query and include the rule that the book with ISBN '0131016210' always should be included - then the query take several seconds to finish: SELECT * FROM C_BOOK WHERE MATCH(NAME) AGAINST ('java') AND (ISBN LIKE '0%' OR ISBN LIKE '1%') OR ISBN = '0131016210' ISBN is the PRIMARY KEY. Is there anything I can do about this?
View Replies !
JDBC Result Closing Takes Ists Time
i am reading 1000 Elements from a database (500.000 all together). The problem is reading the data takes only a few miliseconds but closing the ResultSet takes another 22 seconds. My Hard Disk tells me that the ResultSet is probably running to the end of my table row by row. Is there a way to tell mysql not to do this ? Statement tempStmnt = aConnection.createStatement(); tempStmnt = aConnection.createStatement( java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); tempStmnt.setFetchSize(Integer.MIN_VALUE); Date tempStart = new Date(); ResultSet tempRs = tempStmnt.executeQuery("SELECT * FROM ARTIKELSTAMMDATEN"); int tempXx = 0; while (tempRs.next() && tempXx++ < aCount) { tempRs.getString("artikelBezeichnung"); }
View Replies !
MYSQL Database Alteration, Repair And Restore Takes Huge Time
I am trying to run alteration queries on one of my mysql tables which has more then 22,00,0000 lakh records. Its been 23 hours and the process is still running (I have to close all the sites running on server due to same). My server specifications: Red Hat 9.0 Pentium 4 3.0 GHz 2 GB Ram, Burst RAM 5 GB Running webserver, mail server as well. Is there a way I can view the minute process details, as what table record is being updated ?
View Replies !
LIKE And IS NOT NULL
Are the LIKE and IS NOT NULL options available in MySQL - these 2 options are availble in Access and MS SQL. LIKE is for searching using wildcards - e.g WHERE Name Like 'AD%'.
View Replies !
Getting The Null
I have two tables to compare Code: Schedule of Subject(table 1) previous subject taken(table 2) Semister ID Subj ID | Semister ID Subj ID 1 1 | 1 1 1 2 | 1 2 1 3 | 1 3 1 4 | null null 1 5 | null null My PK for this should be Semister ID. My table 2 has only 3 records, so obviously if I compare table2 from table1 (which has 6 records), table 2 should show the null value because it has no record for the following semister and subjects.
View Replies !
NULL/NOT NULL
I'm drawing a blank when it comes to using NULL/NOT NULL in my tables... can someone refresh my memory about this option in laemen terms. Also how or why does the field with this option have "NULL" entered in the field as the default value?
View Replies !
NULL Or Zero
`timestampLastFailedLogin` int(11), If there is no value(field was never accessed or used) should I leave it with NULL value or should I give it 0 as default value as follows? `timestampLastFailedLogin` int(11) UNSIGNED NOT NULL DEFAULT '0'
View Replies !
WHERE A OR B OR C IS NOT NULL
I am trying to sort my recordset so that records will only display if certain columns contain information. I am unsure of the syntax on this. My first two columns will always be populated with data, but I only want to display the record if any one of the rest of the columns contain data. I know that .Code: SELECT * WHERE a OR b OR c IS NOT NULL is not quite right.
View Replies !
Using NULL Vs 0
I have a DB i MySQL that uses many int(1) type fields. I store there some time value 0 or NULL. My question is which solution is faster from DB point of view? Should I store NULL for all those fields or is "0" better solution? Which one takes less space and time to process?
View Replies !
NULL And NOT NULL
I understand the meaning of NULL, but I don't understand its usage. For example, a field declared to be NOT NULL, but has a NULL value. Or when a field is declared to be NULL, and yet values can still be placed into it. I don't understand the logic behind this.
View Replies !
IS NOT NULL
I tried below mentioned sql statement mysql> SHOW COLUMNS FROM Country WHERE `Default` IS NOT NULL; and suprinsgly it even list down those record as well where coloumn 'default' is NULL Note : In the preceding statement, the column name (Default) must be given as a quoted identifier because it is a reserved word. Any specific reason why it produced record having value as NULL, i tried somewhat similar to my own table , and it works fine for my other table.
View Replies !
WHERE Id NOT IN (NULL)
CREATE TABLE t (id INTEGER PRIMARY KEY); INSERT INTO t SET id=1; SELECT * FROM t WHERE id NOT IN (2); # one row SELECT * FROM t WHERE id NOT IN (NULL); # empty set This is a big surprise, since in my mind 1 is not in (NULL). Here's another strange difference: SELECT (1 IN (NULL)); # (NULL) SELECT (1 IN (2)); # (0)
View Replies !
Null OR Value
how can I write a query that will return results that are either null or a specified value e.g. e.g something like SELECT * FROM Table 1 where ID = null OR 5
View Replies !
Null Vs Not Null
I create a field in a table as a "Not Null" would this prevent a new record to be created unless that field is properly filled? I'm playing around with a test website and I tried leaving blank a "Not null" field but the record was created anyway with that field empty. Maybe I'm not understanding the Null vs Notnull stuff correctly? If so, how would one restrict the creation of new records unless a not null field contains valid (or data at all) data?
View Replies !
What Should Be NULL Is Zero
I am collecting user feedback via an HTML form and sending it to a DB via a PHP form handler. My problem is that values that should be NULL are showing up in the DB as zero. When a user skips a question, I want the value for that field to be NULL. In the form, I set the variables used to capture the user's choices to default to NULL (not enclosed in quotes). All the PHP handler does is gather the submitted values and send them off to the database. When I echo the variables from the form handler, they are NULL. In the database, the fields are defined as INT(1) with a NULL default value. But when the values (which should be NULL) are submitted to the DB via the form handler, the resulting fields are zero. (I have also tried setting the form's default values to "" and '' with the same result.) What can I do to make these values NULL?
View Replies !
NOT NULL Vs. NULL
I have a table that's populated by a form. There are some fields that are optional. Should I send empty strings to a NOT NULL column or should I set the column as NULL and send nothing at all? Am I right in interpreting the meaning of NOT NULL by saying: NOT NULL means an INSERT will fail if the corresponding field is left out of the query?
View Replies !
Null Or Not Null
I am setting up my db, and am reading a great book on all of this, but am confused on exactly when to use null and not null.
View Replies !
Using NULL
I was wondering is it good practice to use NULL for unknown values? In the PHP forum sticky it says: 2) Declare all of your columns NOT NULL unless you need to store NULL values (NULL is not the same as 0 or the empty string). If you need to store NULL, you'll know. Again, NOT NULL saves space and speeds things up. In the fields I am thinking of storing NULL, I could instead use empty string in the CHAR fields, and 0 in the numeric fields. However using NULL would make life a bit easier, and is probably more readable. Should I use NULL? Or, is it better practice to avoid it where possible and use 0/""? Or, am I misunderstanding use of NULL altogether?
View Replies !
Not Null
I can't seem to find a comprehensive or accurate answer on this subject. Is it more work and/or overhead for mysql to mark a column as not null? IE, should I keep columns as NULL whenever possible? If the column is allowed to be null but I also provide a default value, will the default be chosen if no value is provided? If the column is not allowed to be null and I don't provide a default value, will a default be chosen? IE 0, false, "", etc
View Replies !
Null Defaults
If I have setup mysql with strict_trans_tables, will MySQL allow "null" defaults in "not null" columns? If the answer is yes, will that information be reflected when I ask for metadata (column information, etc.)? Currently, when I ask for metadata information, not-null columns will return a default of "empty string". As additional information, I currently use 5.0.21-community-nt
View Replies !
Sort NULL Last
I have a mysql query, "SELECT * FROM task ORDER BY duedate ASC", where "duedate" is a unix_timestamp and can be NULL. I want any NULL results to be at the end of the list, how might I do this?
View Replies !
When To Use 'NOT NULL' In Tables
My database receives HTML form values (text, I don't store binary files in any of my tables).When is it adviseable to create a table column with NOT NULL?I make a habit of having all my table columns this way but wonder if I am just putting additional overhead (however small) on the server and getting zero advantages.
View Replies !
Count() Null=1
Whenever I use the aggregate function count with a left join the NULL values like to COUNT() themselves as 1. Does anyone know what's causing this or how to fix it?
View Replies !
Dealing With NULL
Is there a why to instruct MySQL to deal with NULL values in a particular way? For the following query, I want the result to be zero and not NULL if v1 or v2 is NULL: SELECT t.v1 * t.v2 FROM table1 t; For the following query, I want no spaces and not NULL to be concatenated if v2 is NULL: SELECT CONCAT(t.v1," ",t.v2) FROM table1 t;
View Replies !
Enter Null As Value
i have a dropdown box with the first box's value as "null" if they do not select it. However, when i enter the value into the db through query it returns it as 0. is there anway so it is null in the db?
View Replies !
Getting NULL For Results
SELECT DATEDIFF('date_hired,'date_fired') from users and i get all NULL for results i think i should be getting number of days apart from the two dates date_hired and date_fired are both date columns so whats wrong with this
View Replies !
If NULL, Get Value From Second Column
I used to do it many times in the past but now I completely forgot the syntax, so here I go: What I want to do is select from one specific column, if this column is empty (NULL or = "") get the value from a second column instead. I remember doing it with a single query, but now I can't seem to remember or find how to do that.
View Replies !
|