Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    MYSQL




Check Empty Table In Where Clause?


the following where clause (expurgated) suits my needs right up until the table emailman is empty (which it frequently is) and then it returns an empty set (which is bad;-)
this is actually an AND emailman... but don't I think the rest is relevant.

WHERE emailman.related_id != contacts.id How can I modify this to allow for emailman to be empty? Something like...

AND (emailman.related_id != contacts.id || NOT EXISTS (emailman.id) )




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
How To Check Empty Columns In A Table
If i press a button, i have to check if certain columns(fields) in a table are empty.If they are empty, i want to send an e-mail to the e-mail address which is already in this table.If there are no empty columns, then i want to do some calculation using another table.

How To Check If Field Is Empty Or Null?
I have a problem. I store some avatar images in a database. And these avatars are optional for each user.

A general unknown avatar image is shown if the avatar field for the specified user is empty or null. Showing the avatar is a 2 step process.

First I want to check if the avatar field is not null. If it is not then retrieve the data and show it on the web page.

Implementing The CHECK Clause`
I am working with mySQL version 4.1.14-max on an Apple Mac. I have been tring to finish up a homework assignment to create the following domain:

CREATE DOMAIN Id INTEGER CHECK ( VALUE > 999 AND VALUE < 99999);

and can't seem to get it to work. I also try addeding the CHECK clause directly into the table, which worked. But, the table is not enforcong the range requierments. After searching the web, I found that mySQL will parse and ignore the CHECK clause when used with CREATE TABLE. So, I have no idea how to restricted the range on the Id attribute.

What Query To Check If Any Rows Exist Satisfying WHERE Clause?
I'm looking for a query that will check if any rows exists in a table according to a WHERE condition. I know I can use COUNT(*) but then mysql will do unnecessary task of counting all the rows whereas I just need true or false. So far I did this:

SELECT COUNT(*) AS exists FROM mytable WHERE ...
Sometimes I just select the first row and check later in php how many rows have been returned:

SELECT some_col FROM mytable WHERE ... LIMIT 1
But I cannot do this check (or can I?) in sql alone and I have problems when I want to use this in a subquery, for example:

SELECT id,
name,
(SELECT COUNT(*) FROM mytable WHERE ...) AS exists
FROM othertable
WHERE surname='xxx'
Can I do the same without using COUNT(*)? I would like a query that returns 0 or NULL if no rows were found, or 1 (or some other value) if 1 or more rows were found.

Reference To Table Alias In From Clause To Be Used By Subquery InSelect Clause
I am using 5.0.26-NT on Windows 2000.

I have need to use a reference in the outer from clause in a subquery in
the select clause. Consider the following example:

Select (select b.baitID from b where b.entrydate curdate()) as
wantedBaitIDs from bait_tbl b;

My actual need is more complex than this as part of it is a rough cross
tab. If I try to define the table in the alias, not only do I lose
whatever benefits there are in the particular join I would use in the
outer from clause but would also require the join to be defined in each
subquery, requiring it to be examined each time it is used.

To be absolutely clear, in this example I want to use bait_tbl with the
alias of b in the subquery. In my actual query I reference the same
table twice with a different join set for each. I need to reference a
particular alias as that has the join set I need.

Check Table And Repair Versus Optimize Table
I am confused about the difference between running a CHECK table and REPAIR(if necessary) versus running an OPTIMIZE table. It's not very clear in the documentation, but seems that OPTIMIZE table does a check and repair in addition to the other functions performed by optimize.

I have inherited some legacy code that does a check and repair and optionally follows it with an optimize. That seems redundant to me and I would like to streamline the code to make it an "either-or" selection.

Table With No Name (empty)
Somehow I managed to created a nameless table, how can I delete it?

Using PHPmyAdmin fails brilliantly, commandline using "drop table '';" fails
as well.

How To Check For Date/time Ranges Within Record (check For Schedule Conflicts)
You want to check scheduling conflicts and you have a record like:

appointments(table):
apptID
beginningDate
endingDate
beginningTime
endingTime

It's easy enough to check if a time is within that record. Say you want to
check if 8:00am to 10:00am is available, you would use this:

SELECT apptID
FROM appointments
WHERE (beginningDate = '2006-01-19' OR endingDate = '2006-01-19')
AND ('08:00:00' BETWEEN beginningTime AND endingTime
OR '10:00:00' BETWEEN beginningTime AND endingTime)

BUT, what if you have an all-day appointment (8:00am to 5:00pm) and there
exists an appointment already scheduled from 10:00am to 11:00am. The above
query would not find it.

Another question is what if the appointment is more than two days. Say, it's
from Monday - Wednesday from 8am to 5pm. The above query would not
successfully catch it if you wanted to schedule an appointment on Tuesday.

(I might be able to generate a date range using PHP, don't know if that's
the best way)

No Return Value From Empty Table
I'm new here so I don't know if this has been discussed earlier.

I have a problem with the following:
SELECT IF(column = 'string', 'a', 'b') AS test FROM table;

It works just fine if the table is populated. However, if the table is empty
(which this one very well can be from time to time) I get no return value at
all.

Is there any way I can get MySQL to return "test = b" if the table is empty?

No Return Value From Empty Table
I have a problem with the following:
SELECT IF(column = 'string', 'a', 'b') AS test FROM table;

It works just fine if the table is populated. However, if the table is empty
(which this one very well can be from time to time) I get no return value at
all.

Is there any way I can get MySQL to return "test = b" if the table is empty?

Empty MySQL Table
I have done a search but can't find the answer to this question:

MySQL - 4.1.21-standard phpMyAdmin - 2.8.0.2

I tried to "empty" one of the tables in a recipe script to remove the number of "views" that appeared on the page. It seemed to work, but when I went back to the website, the number of views didn't change. Is there something I am missing?

Process Table Is Empty
We use MySQL 4.0.13, Redhat 7.3(kernel 2.4.18.3). Apache 1.3.27
Mysql is alive and there are process but I don't see in ps (process
table) and very slow web receive.

How Can I Count Non-empty Fields Of A Table
there's a form with some fields, after submitting, all non-empty inputs are in mysql table's field. how can i count how many are non-empty fields in a row of mysql table?


Join Table With Empty Data
I'm a novice, and am having issues get a JOIN to work properly. The following code is correct for pulling field values that HAVE a value, but when a field i am requesting has a value like Null, Space, or just empty, the whole query comes back empty.

It was suggested i use TRIM in my call, but i'm not exactly sure how to use properly.

As far as each table, the fields that are empty are set to ALLOW NULL.
PHP

Select
company.company_name,
company.company_username,
company.company_clients_served,
company.company_status,
note.note_text,
address.address_street1,
address.address_street2,
address.address_zip,
address.address_zip_ext,
county.county_id,
city.city_name,
taxes_states.state_id,
email.email_address,
url.url_path,
url.url_name,
company_type.company_type_id
From
company
Inner Join note ON company.note_id = note.note_id
,
address
Inner Join connector_address ON company.company_id = connector_address.ref_id AND connector_address.address_id = address.address_id
Inner Join county ON address.county_id = county.county_id
Inner Join city ON address.city_id = city.city_id
Inner Join taxes_states ON address.state_id = taxes_states.state_id
Inner Join connector_email ON company.company_id = connector_email.ref_id
Inner Join email ON connector_email.email_id = email.email_id
Inner Join connector_url ON company.company_id = connector_url.ref_id
Inner Join url ON connector_url.url_id = url.url_id
,
company_type
Inner Join connector_company ON company_type.company_type_id = connector_company.company_type AND company.company_id = connector_company.company_id
Where company.company_id = &#3915;'

Empty Value In Multi Table Query
MySQL
SELECT p.`desc` ,
    IF(SUBSTRING(p.prodCode,1,3)='p1-',(SELECT p2.nPrice FROM tProducts p2 WHERE p2.prodCode=SUBSTRING(p.prodCode,4) LIMIT 1),0) as normalPrice,
    COUNT(DISTINCT pic.ordering) as pic_count
FROM
    tProducts p
    JOIN prod_subCats psc ON p.productID=psc.relProdId
    LEFT JOIN taxCodes tax ON p.taxCode=tax.taxCode
    LEFT JOIN suppliers s ON p.supplierID=s.supplierID
    LEFT JOIN pictures pic ON p.productID=pic.relProdId
    LEFT JOIN freeProducts fp ON p.productID = fp.productID
    LEFT JOIN tProducts freeProd ON fp.freeProductID=freeProd.productID
    LEFT JOIN pictures freePic ON freeProd.productID=freePic.relProdId
    LEFT JOIN prodReviews review ON p.productID=review.productID AND review.status=1
   
    WHERE p.stocklevel>-3 AND psc.relSubCatId=7235
    GROUP BY p.productID
LIMIT 1

The value p.`desc` comes up blank (not null, just blank) in this query, though I know this data is there.
If I remove either of the other 2 fields for the query, the correct data for field p.`desc` is returned.
This kind of thing would normally happen when you specify fields with the same name from different tables, either explicitly, or using *. But as far as I can tell, all my fields & tables are correctly aliased etc
To further confuse matters, this problem occurs on my (windows) development server running v4.1.1, but not the (linux) production machine running v 4.1.2
I'm stumped.

Ignore Empty Links In Table
I have a set of tables like so:

category -> subcategory - gallery -> gallerylink-> images

each linked by a parentid

category - holds a categoryID
subcategory table is linked to category via categoryid
gallery linked to subcat via subcatid
gallerylink holds galleryid and imageids
images linked to gallery via gallerylink table

Ok so I am trying to get a random imageid(to display a thumbnail) out of my images table for a specific user. At the point I run this query, all I have is the userid. Here is my query:

select CategoryID from category where UserID = 1 ORDER BY RAND() limit 1

I then take the categoryid I get here and my userid and run a more specifc query to get the imageid I need using all the linked tables.

The problem is when I run this categoryid query, it is possible that it grabs a categoryid that has no subcategory assigned yet, or gallery or images. So I only want to look at categoryids to which have a record in the subcat table and the subcat table has a record in the gallery table and it has a record in the gallerylink table.

So the categoryid that is randomly selected has to be linked all the way to an existing image. How do I accomplish this without running 4 separate queries?

Skip Empty Table When Create Them
I am working on a big table that I need to turn into little tables using customernumber a lot of times the customernumber has no movements, the table appears with zero rows, so I want to tell the SELECT I use to not create the table if its zero rows, this is how I have it right now

CREATE TABLE $tableNameexpt SELECT * FROM final_exp WHERE pat = $row[0]

the last part is like that because I am programming in perl, when run it creates these table with zero rows, how can I avoid them ????

Check If A Table Has Been Updated
I'd like to find a way to check if any modifications has been made to a table. I'm using mysql 4.1. I'm trying to find the least resource intensive method of doing this.

Check Table For An Entry?
I'm currently working on some rudamentry administration, namely an IP ban list. I want to make it so that if the user trys to ban an IP that is already in the list, the entry will be removed instead. what would be the best way to go about this?

Check If Table Exsists
Am creating an install.php page to create the tables for a database. After running the code I want to make sure the tables were created, how do you check is a table exsists in mysql?

Check If A Table Exists
is there any way to check if a table exists in mysql? i am using a graph program in vb, but if the table it is trying to graph doesnt exist it breaks down! i need some sort of check so as the offending table will not be added to the query if it doesnt exist?

Load Cvs Data Into An Exisitng Empty Table?
how do i load cvs data into an exisitng empty table?
i've tried to follow the syntax for the doumentation manual- the load infile... statement but it doesnt work, it says file not found

i also tried to use the import option with the phpMyAdmin GUI but it gave me an error saying check the syntax on that one. and there isnt any syntax to check b/c its just a file that i saved as csv and tried to import.

How Do I Check If An Table Index Exists Via PHP ?
I was wondering if it's possible to verify if an table index already exists or not? As it's possible to add indexes multiple times.

Check If Row Exists In Anotehr Table
Is there a way to check if a certain value exists in another table without using something like

SELEC * FROM tbl WHERE someid = 'somevalue';

and seeing if it returns false

I ask this because I'm running a kind of search query where it selects all records from a table where this field is this, that field is that, etc.

So for example

SELECT * FROM members WHERE id='this' || name='that' || height='67' || etc..etc...

now one of the attributes is a zip code.

In another table, i just ahve a list of like a billion zip codes. Ifi want to check if the zip code exists in this list in this other table, how would i do so while preservingn the above format in one call?

Check Table Wildcard Syntax?
I need to do CHECK TABLE on a lot of tables (actually on all tables in
several databases), and hoped to do something like

mysql> CHECK TABLE reports.*

which ddn't work. The only thing that seems to work is using
cut'n'paste (or some scritpting) to get a comme seperated list. Is
there really no "smart" way of doing this?

Check Table Command - When To Use Which Checking Option
I'm trying to decide which check table option to use for a DB-health-check script for my product. This script is to be run periodically to find and repair damaged tables. My product uses only MySQL, i.e. it does not interact with another DB. I need to find the check table option that would find damaged tables with the highest possible performance.

The 13.5.2.3 CHECK TABLE Syntax documentation states the following:
MEDIUM Scan rows to verify that deleted links are okay. This also calculates a key checksum for the rows and verifies this with a calculated checksum for the keys.

What are they referring to with the word "links"? Are they talking about links to MS Access tables? How do I know if my tables have links? Does the MEDIUM option scan rows only to check deleted links? If so, if I don' t have "deleted links", should I not use this option? By running in MEDIUM mode, will the tables be locked while "check table" is working?

For the other options - CHANGED, FAST, QUICK - will "check table" lock the tables? What access do I have to the tables while check table is running?

You Can't Specify Target Table '' For Update In FROM Clause
I have problem deleting rows from table with subquery referring to the same table. I store tree structure in the table (there is ParentID field for each row that specifies primary key of the parent row). I'm trying to delete all children of the given row which doesn't have their own children. I can't do this from the script by iterating through all rows because there could be thousands of such records.

I thought that the following query will do that:

DELETE P FROM `tree` AS P WHERE P.`ParentID` = @parent AND NOT EXISTS (SELECT * FROM `tree` AS C WHERE C.`ParentID` = P.`ID`)

But this doesn't work, throwing error:

You can't specify target table 'tree' for update in FROM clause

How can I make this work?

Unknown Table 'xxxx' In Where Clause
I have been looking through a few of the forum posts here and I haven't found a solution to my problem.

There error I am getting is:
Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[MySQL][ODBC 3.51 Driver][mysqld-4.1.7-nt]Unknown table 'girls' in where clause

/xxx/xxx.asp, line xxx

[asp]
Dim RSGirls
Dim RSThumbs
Dim GirlSQLStmt
Dim ThumbSQLStmt

GirlSQLStmt = "SELECT Name, Height, Age, Weight, Bust, Waist, Hips, Pictures, Description "
GirlSQLStmt = GirlSQLStmt & "FROM Girls"

ThumbSQLStmt = "SELECT * FROM tourthumbs WHERE tourthumbs.id = girls.id"

Set RSThumbs = MyConn.Execute(ThumbSQLStmt)
Set RSGirls = MyConn.Execute(GirlSQLStmt)
[/asp]

There are two tables in the database, 'girls' and 'tourthumbs'. I have checked the permissions that I have set for MySQL and made sure that I can access them both. Both tables also exist and so does the id field in both tables.

You Can't Specify Target Table 'ubs' For Update In FROM Clause...
UPDATE ubsc SET date = NOW(),xp_date = now() WHERE ubs_id = (SELECT MAX(ubs_id) FROM ubsc WHERE ubsd_id =(SELECT ubsd FROM ubsd WHERE ubsf_id = 1009))

The above query shows me error

You can't specify target table 'ubs' for update in FROM clause...

Create Table Error. #1064 - You Have An Error In Your SQL Syntax; Check The Manual That Corresponds
I have been trying to create two tables with the SQL below. I have the SQL in file and tried to import it to PhpMysqlAdmin in my control panel. The wierd thing is that the first table gets created while the second one is not created and error is thrown instead. The error message is

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ....

Empty Set
I'm learning how to use MySQL at the moent and according to my book I needed to load data into the table president I created from a file, so I gave the following command:

LOAD DATA LOCAL INFILE "C:/samp_db/insert_president.sql" INTO TABLE president;

Reply:

Query OK, 42 rows affected, 294 warnings (0.01 sec)
Records: 42 Deleted: 0 Skipped: 0 Warnings: 294

When I now try to search for data I get the following result, this is the way I'm trying to do it.

SELECT last_name, first_name FROM president
WHERE last_name="ROOSEVELT";

Reply:

Empty set (0.00 sec)

This is a part of the file:

DELETE FROM president;
INSERT INTO president VALUES ('Washington','George',NULL,'Wakefield','VA','1732-02-22','1799-12-14');
INSERT INTO president VALUES ('Adams','John',NULL,'Braintree','MA','1735-10-30','1826-07-04');
etc.

Could any one see what I am doing wrong here?

Empty Set
how do i validate if a 'mysql_query' statement returns an 'empty set'?

this not works.........

$result=mysql_query($query,$con);
if(!$result)
{
echo "Error";
}

Get The Least Empty Value
How can I get the least empty value?
For example,

value
=====
1
2
4
6
7
8
=====

I have to get 3.

Why Is My Dataadapter Empty?
When i run my application i get the following error on the highlighted line :: Additional information: Value cannot be null.

Dim connStr As String
        connStr = String.Format("server={0};user id={1}; password={2}; database=prodev; pooling=false", "main", "root", "root")
        Dim Excel As New Microsoft.Office.Interop.Excel.Application
        Dim dsExcelExport As DataSet
        Dim conn As New MySqlConnection(connStr)
        Dim daExcelExport As MySqlDataAdapter
        Dim intColumn, intRow, intColumnValue As Integer
        Dim strExcelFile As String
        Dim strFileName As String

        daExcelExport = New MySqlDataAdapter("select * from users", conn)
        daExcelExport.Fill(dsExcelExport)

Value Of Empty Cells?
If you try to access an empty cell of a database with a SQL database query, and you assign a PHP variable to the cell value, what is the value of that PHP variable? Zero? Null?

so...$variable == 0 ?? or maybe, $variable == NULL ??

Empty Result Set
I'm running a perl script that accesses a mysql database.  I'm trying to run a simple select statement that gives me an empty result set.  The wierd thing is that if I simply replace the table name with another table name - the statement returns stuff.  Could the one table have some sort of issue with it?

Empty Password
Does the mysql v4.1.7 allow empty passwords for the root user? cuz i noticed that without a password my program turns up a java.sql.Exception then access denied.

Empty Category
I'm sure most of us are familiar with the infinite-depth category system, where all categories are in the same table and each has a parent id referring to 0 (top level category) or the the id of another category.

Is there a fast way to return these categories, but only if the category, or the child category (or the grand child, or so on...) has a product in it?

I know that you can essentially do (sorry if this is a little rough, I'm more SQL-Server, so I tend to lean towards it when I'm giving examples).

CODESelect * from cats
 where catParentID = #url.catParentID#
   and catID in (select catID from products)

Delieting Empty DBs
Somehow I can not delete empty databases.
When I drop a database, it deletes all tables but not the DB.
When trying to drop DB again, it tells me query ok, but the DB still exists.
Sometims when droppting a DB, it deletes all but one table.... when I try to delete this table then, I get file not found errors...
Is there a trick to force deletion of a DB... no matter if there is something corrupt or whatever?

Error:Query Was Empty
What could be the cause of the above error
message to appear along with my error echo messages.

Adding Empty Row In Result Set?
In a select query, what do I add in order to add an empty row either at the very top or at the very bottom of the result table even if the result set is empty?

Empty String Vs. NULLL
I have just spent hours figuring out what my problem was, when I realized that an empty string is not the same as NULL. But I'm curious, is there a way to coerce empty strings into NULL? Or, is there a version of COALESCE that works with empty strings?
The following code exemplifies my problem:
create table test (
id int auto_increment primary key,
data text);
insert into test set data=''
insert into test set id=id;
select coalesce(data, 'no data exists') from test;
+----------------------------------+
| coalesce(data, 'no data exists') |
+----------------------------------+
| NULL |
| no data exists |
+----------------------------------+
I particularly would like an empty string to evaluate as null because I am dealing with user form submissions. It would be an extra step to convert to actual null (not empty string), or to check each field and not include in my insert if that field is empty.
I was tricked so easily since empty string displays as null. Is there a way to turn that off so an empty string looks like an empty string?
What is common practice in this scenario?

!empty() Speedy Equivalent
Very simple one, I'm in the optimization phase and have a bite-sized question if anyone can help--

// Trying to select all news where there is an image
// The field 'image' stores the image's filename
SELECT * FROM news WHERE image != ''

My assumption is that this query is slow, naturally, compared to adding a new field called has_image with a value of 0 or 1 and running:
SELECT * FROM news WHERE has_image = 1

Is this a sound assumption that the latter would be faster than the former? It does seem a little redundant though to add a new field. Is there a 'best' way to accomplish this task?

Random Empty Records
I run a WAMP webserver and host an online entry form for a local running race. I'm getting random empty records inserted into the database. For every 50 or so legitimate entries, I get a blank record or two. A few people have said they signed up, but their infomation is not in the database. At first I thought it was user error, but now I'm not so sure. Has anyone else experienced a problem with random blank records inserted in thier database? Any guesses?

Java Empty Resultset
I create some java code to get data from a table. Everything is fine. Except, that the ResultSet is empty, i.e. it contains no data, it is not null, though. BUT the table has data in it, if I execute the sql-statement directly in mysql, it works fine. Here is my code: Code:

Adding Empty Row In Result Set?
In a select query, what do I add in order to add an empty row either at the very top or at the very bottom of the result table even if the result set is empty?

Searching With Empty Fields
Can you tell me what SQL would enable me to search with empty fields?

For example using a search form with username, firstname & surname, allow users to search for a person with 'joe' as a firstname but if they leave the surname field blank it will return ALL 'Joes' in the database regardless of surname and username. Similarly search for a surname without the other two?

In MS Access, it will return all records using blank fields but in MySQL it won't.

I could program an if statement to cover all possible combinations but surely there is a better way?

Order By Another Collumn If Empty
I've got a Table with a few fields, three of them are company, name and lname. My problem is, not every record has a company and I want to sort a list in either company or name + lname depending on if the company field is filled. Code:

Empty Field Or Null
In a table if you have a field that is empty, does it still hold that space?

And also, if you put a Null value in it does that change anything?


Copyright © 2005-08 www.BigResource.com, All rights reserved