Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: dlaczego nie dziala IS NULL?
Forum PHP.pl > Forum > Bazy danych
ins@ne
Mam taka tabele:
NrKli | Tytul | Nadrzedna
Wpisow jest kilkadziesiat (NrKli i Tytul sa zawsze, Nadrzedna bywa pusta). Po zapytaniu:
[sql:1:cc7321ac88]select NrKli,Tytul from klienci where Nadrzedna IS NULL[/sql:1:cc7321ac88]
SQL nie zwraca zadnych wynikow. Probowalem juz zmienic wlasciwosc pola Nadrzedna w phpmyadmin (Null) na null albo na not null, ale to nic nie zmienia :|. Nie bardzo wiem co jeszcze moze byc przyczyna tego...
Lucky
To chyba powinno być tak:

[sql:1:0320781bfa]SELECT NrKli,Tytul
FROM klienci
WHERE Nadrzedna = NULL[/sql:1:0320781bfa]
spenalzo
Cytat
To chyba powinno być tak:

RTFM. :!:


ins@ne: zapytanie jest jak najbardziej poprawne, ale
a) masz rekordy z NULL ?
cool.gif masz typ pola z NULL ?

Cytat
Nadrzedna bywa pusta

Pusta != NULL !
NULL to jest NULL i nie może być wartością pustą, lub zerem.
ins@ne
spenalzo: do konca chyba nie wiem o co pytasz z tym czy mam rekordy z null... caly opis pola wyglada tak:
Kod
Nazwa     | Typ  | Null | Domyslnie

Nadrzedna | text | Tak  | NULL

Hmmm... co do tego, ze pusta to nie null... Mi sie wydawalo zawsze, ze NULL oznacza wlasnie puste pole... Przynajmniej tak mnie uczono :|. Mniejsza o to zreszta - przy tworzeniu tabeli pole zostalo ustawione jak napisalem wyzej, a wartosc nie zostala tam po prostu wpisana - nie wiem czy jest to NULL czy pusta (wedle Twojej nomenklatury). Bede wdzieczny jesli poswiecisz mi chwile na wyjasnie tej niedostrzegalnej dla mnie roznicy smile.gif.

btw. co znaczy RTFM?
DeyV
RTFM - Read The Frendly/Fucking Manual - skrót, który powinien znać każdy.


Cytat
A.5.3 Problems with NULL Values


The concept of the NULL value is a common source of confusion for newcomers to SQL, who often think that NULL is the same thing as an empty string "". This is not the case! For example, the following statements are completely different:

mysql> INSERT INTO my_table (phone) VALUES (NULL);
mysql> INSERT INTO my_table (phone) VALUES ("");

Both statements insert a value into the phone column, but the first inserts a NULL value and the second inserts an empty string. The meaning of the first can be regarded as ``phone number is not known'' and the meaning of the second can be regarded as ``she has no phone''.

In SQL, the NULL value is always false in comparison to any other value, even NULL. An expression that contains NULL always produces a NULL value unless otherwise indicated in the documentation for the operators and functions involved in the expression. All columns in the following example return NULL:

mysql> SELECT NULL,1+NULL,CONCAT('Invisible',NULL);

If you want to search for column values that are NULL, you cannot use the =NULL test. The following statement returns no rows, because expr = NULL is FALSE, for any expression:

mysql> SELECT * FROM my_table WHERE phone = NULL;

To look for NULL values, you must use the IS NULL test. The following shows how to find the NULL phone number and the empty phone number:

mysql> SELECT * FROM my_table WHERE phone IS NULL;
mysql> SELECT * FROM my_table WHERE phone = "";

Note that you can only add an index on a column that can have NULL values if you are using MySQL Version 3.23.2 or newer and are using the MyISAM or InnoDB table type. In earlier versions and with other table types, you must declare such columns NOT NULL. This also means you cannot then insert NULL into an indexed column.

When using ORDER BY, NULL values are presented first. If you sort in descending order using DESC, NULL values are presented last. When using GROUP BY, all NULL values are regarded as equal.

To help with NULL handling, you can use the IS NULL and IS NOT NULL operators and the IFNULL() function.

For some column types, NULL values are handled specially. If you insert NULL into the first TIMESTAMP column of a table, the current date and time is inserted. If you insert NULL into an AUTO_INCREMENT column, the next number in the sequence is inserted.
Lucky
Nie byłe mpewien, dlatego napisałem "CHYBA", ale widzę że Spenalzo sam chyba nie wie gdzie to jest w manualu skoro potrafił napisać tylko RTFM. Natomiast dzięki ci DeyV za fragment smile.gif .
scanner
Cytat
Spenalzo sam chyba nie wie gdzie to jest w manualu skoro potrafił napisać tylko RTFM.
To forum nie służy do wklejania tekstów z manuala. Twoim obowiązkiem jest zajrzeć tam osobiście i wpisać w ichnią wyszukiwarkę odpowiednie słowo kluczowe.

EOT
Lucky
A kto mówi o wklejaniu tekstu. Wystarczy przecież odnośnik. To tak jak przeszukaj forum, lepiej z odnośnikiem (przecież). Post typu RTFM nic ciekawego nie wnosi do forum?questionmark.gif Nie mam racji?
spenalzo
Cytat
A kto mówi o wklejaniu tekstu. Wystarczy przecież odnośnik. To tak jak przeszukaj forum, lepiej z odnośnikiem (przecież). Post typu RTFM nic ciekawego nie wnosi do forum?questionmark.gif Nie mam racji?

Nie mam czasu ani ochoty, żeby LENIOM podawać linki - wyszukanie tej informacji zajmuje 30 sekund.

Nie lubie jak ktoś filozofuje i co gorsza nie umie sie przyznać do błedu.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.