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




Testing For An Empty Set Returned By A Nested Select Statement


For those of you following the "While Loop Within Select" thread... I've been restructuring my database to incorporate the changes. Now I've got a table of skipped stops rather than a table of stops (I need it that way for various reasons) and I need to return the schedule to the user as long as the user's stop isn't in the list of skipped stops. SO say something like:

SELECT
yada yada yada
FROM
schedule AS 's1'
WHERE
(
SELECT
skippedstop_id
FROM
skippedstops
WHERE
schedule_id=s1.schedule_id
AND
location_id=$origin
) == "EMPTY SET"

Only I have no idea how to actually test for the empty set from the nested select...




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Testing Parameters Within A SELECT Statement
I am building a SELECT statement where I will be passed search parameters depending on what user has entered. Each parameter may have a value or maybe NULL.

What construct (CASE, IF, etc) can I use to build my WHERE clause so that the passed value is included or if NULL, all rows are returned.

SELECT *
FROM table
WHERE col_a = val_a (or if VAL is NULL then all rows)
AND col_b = val_b (or if VAL is NULL then all rows)
AND col_c = val_c (or if VAL is NULL then all rows)
etc ...

Nested Select Statement Error
the mysql that is loaded on the host i am on is mySQL 4.0.24 whereas the one i am using is mySQL 5.0.27 on my computer.

i am having some weird problems where nested statements like this are not working on the server i am on...
select * from table1 where id = (select id from table2 where user = 1);

this sql statement works fine on my computer but not on the server. it says there is a syntax error when it is run on the server. but this sql doesn't look wrong to me, or it does?

i have a feeling that sub queries is not implemented in mysql 4.0 and earlier....but i really don't wish to change all the sql in my scripts to the old method where i have to select * from table1, table2 where table1.id = table2.user; because it will be quite troublesome...

Nested Select In Update Statement
my nested Select-Update-Statement doesn't work. I think it's because the SELECT-Statement returns an empty set.. is there a posibillity to run this statement if there is no empty set and insert NULL if it is? Or is there another error at all?

CODEUPDATE proj_user_suche SET acronym = (SELECT name FROM acronym LEFT OUTER JOIN link_acronym ON acronym.id_acronym = link_acronym.id_acronym WHERE projekte_nr="23") WHERE id_proj_user_suche="17"

Select Statement Question (nested Select?)
I have a DB containing 3 fields fullname, inext, and outext. I need to see all the records that have a duplicate entry in inext. I know I can do a distinct query on the inext column but that only gives me the unique ones I need all the different duplicate records.

Nested Select Statement Taking Hours To Execute
I am running a sub select statment so I can compare a couple of tables. If I run the statement from two test tables of 1000 records in each, it will take nine seconds to get the results that I need.

However, if I take the same statement and point it to the two tables which contain all the data I need to run against (50560 and 161680 records respectively), it takes hours to run...how long I'm not sure. I fired the statement off yesterday afternoon @ 3pm and it is currently 11:30am the following day...the select statement is still executing.

Does anyone have performance on something like this?

SHOW TABLE STATUS & The Nested SELECT Statement
The "SHOW TABLE STATUS" command seems to return a result set, just
like "SELECT * FROM SomeTable".

Therefore, since the following is valid:

SELECT * FROM (SELECT * FROM SomeTable)

I inferred that this functionality would extend to the SHOW statement:

SELECT * FROM (SHOW TABLE STATUS FROM SomeDataBase)

But such a command gives an invalid syntax error.

I want to query the data_length from a few tables, place those values
into temp variables and then run a second SQL command using those
values. Is what I'm trying to do possible?

SHOW TABLE STATUS & The Nested SELECT Statement
The "SHOW TABLE STATUS" command seems to return a result set, just
like "SELECT * FROM SomeTable".

Therefore, since the following is valid:

SELECT * FROM (SELECT * FROM SomeTable)

I inferred that this functionality would extend to the SHOW statement:

SELECT * FROM (SHOW TABLE STATUS FROM SomeDataBase)

But such a command gives an invalid syntax error.

I want to query the data_length from a few tables, place those values
into temp variables and then run a second SQL command using those
values. Is what I'm trying to do possible?

Nested SQL Statement
I'm new to MySQL and I use this frequently with SQL Server 2000. I get an error and want to know if there is something equivalent with MySQL? Code:

Nested While Loop In An SQL Statement
Hope the title isn't too off putting!  

Anyway I am having trouble getting the following to display what I want correctly. Here's the code then I'll explain;


CODE$sql = "SELECT board FROM leaderboard";
$result = mysql_query($sql);
  while($board = mysql_fetch_array($result, MYSQL_NUM))
       {
        $query = "SELECT $board[0].rank, users.username, $board[0].W FROM users, $board[0] WHERE users.id = $board[0].id ORDER BY W DESC LIMIT 50";
         $result2 = @mysql_query ($query);
         while ($row = mysql_fetch_array($result2, MYSQL_NUM))
{echo "<tr><td align="center">$row[0]</td><td align="center">$row[1]</td>
                         <td align="center">$row[2]</td><td align="center">$board[0]</td></tr>";
           }
           }
           echo '</table>';

Convert A Nested Update Statement
i have a nested update statement in my sql server as follows
UPDATE DIM_EVENT .

SET INVOICE_AMOUNT =
(SELECT SUM(INV.INVOICE_AMOUNT_TOTAL)
FROM INVOICE INV
WHERE INV.INVOICE_REFERENCE_NUMBER = DIM_EVENT.OBJECT_ID
AND INV.INVOICE_AMOUNT_TOTAL IS NOT NULL)
WHERE DIM_EVENT.EVENT_TYPE_CODE IN ('OFULN', 'OAUTH', 'CRDRL');
what is the equivalent in MySQL.

Nested Select
is it posibile to select like this:

SELECT *,(SELECT name FROM tablex WHERE cid=table.id) as country FROM table
i would like to give the result from first select as condition for inner select

so i get table.id from first select query wich will be condition for result of inner select

anyway i would like to get result in one row ..like *,country


My Nested SELECT
SELECT COUNT(1) as numapp
FROM post_jobs
(SELECT COUNT(pj.1) as numnot FROM post_jobs as pj WHERE member_id='m2e4m387' AND pj.approval = 0)
WHERE member_id = 'm2e4m387' AND approval != 0
I've looked stuff up online and have re-arranged this in several different ways. Can count not be used within a nested SELECT?



Nested Select Using Like
I am trying to use the results of a nested select statement in the 'parent' statement using 'LIKE' as per:

SELECT * FROM t1 WHERE c1 LIKE (SELECT c7 FROM t2 WHERE ID = 987);

Does anyone know if this is possible? I am getting empty sets when I experiment with the placement of the % signs. For example:

SELECT * FROM t1 WHERE c1 LIKE "%(SELECT c7 FROM t2 WHERE ID = 987)%";
Empty set (0.01 sec)

Also I have tried to assign the result of the nested select to a variable like:
SELECT @v := c7 FROM t2 WHERE ID = 987;

But again then have no idea how to put this variable "@v" into a statement using LIKE.

Have tried:
SELECT * FROM t1 WHERE c1 LIKE '%@v%';
Empty set (0.00 sec)

Nested Select
I'm trying to display a bunch of checkboxes in php and have them
checked/not checked based on the results of the following query but
I'm getting syntax errors. This would work in mssql how would I
accomplish the same thing in mysql?

SELECT tblOrg_Type.ID, tblOrg_Type.Org_Type, (Select 'Checked' from
tblContactOrgType where OrgID = 8 AND tblOrg_Type.ID =
tblContactOrgType.OrgTypeID ) AS Checked
FROM tblOrg_Type;

Table Structures:

tblOrg_Type
ID
Org_Type

tblContactOrgType
ID
OrgID
OrgTypeID

Nested Select
how i can do this:

SELECT  * , (
SELECT pic_path
FROM tbl_newspics
WHERE tbl_newspics.pic_newsid = tbl_news.news_id
LIMIT 1  ) AS pic
FROM tbl_news
WHERE news_publish =1
ORDER  BY news_added DESC
LIMIT 5

Basically I have a news table and a pictures table.  

Nested Sql Select
I have the following mysql tables:

TRANSACTIONS
customerid  int
item        varchar
time        datetime

What i want to do is select all similar items which have been bought within a time frame of say 2 hours. the start and end time don't matter, just the difference.

i can do this with a SELECT item, time from transactions order by time;
( call this rs1 and var item1 = rs1.getString("item"), var time1 = rs1.getString("time") )
and then iterate over the resulset, but this is expensive.
i.e. SELECT item from transactions where item = item1 and time between time1 and (time1 + 2)

can i do this in a single sql expression?

Nested Select
I'm trying to display a bunch of checkboxes in php and have them
checked/not checked based on the results of the following query but
I'm getting syntax errors. This would work in mssql how would I
accomplish the same thing in mysql?

SELECT tblOrg_Type.ID, tblOrg_Type.Org_Type, (Select 'Checked' from
tblContactOrgType where OrgID = 8 AND tblOrg_Type.ID =
tblContactOrgType.OrgTypeID ) AS Checked
FROM tblOrg_Type;

Table Structures:

tblOrg_Type
ID
Org_Type

tblContactOrgType
ID
OrgID
OrgTypeID

NESTED SELECT
I want to select User_ID = 1 and display only TABLE 2 ->Link_ID 300, 500 and 600
In short those TABLE2->Link_ID <> TABLE1->Link_ID.

TABLE 1
User_IDLink_ID
1100
1200
1400
2300
3100
3200
4100
5100


TABLE 2
Link_IDDescription
100a
200b
300c
400d
500e
600f

Nested SELECT
I'm new to MySQL and want to do a nested SELECT statement.
i want to get all years stored in the database except the last year:
(content is the table and null values exists)

SELECT DISTINCT YEAR(content.date)
FROM content
WHERE(((YEAR(content.date)) IS NOT null)) AND YEAR(content.date) < (SELECT YEAR(MAX (content.date)) FROM content))
ORDER BY YEAR(content.date) DESC
What is wrong

How To Improve On A Nested Select
I'm working on a simple data import tool, and I need to insert email addresses from table two into table one, if they don't already exist in table one. I figured this was a pretty easy nested select statement, but what I'm doing is getting my site taken off line for exceeding the CPU limit. Here's the SQL I'm using to get the new email addresses:

SELECT distinct value, id FROM table_two WHERE name = 'email_address' AND value NOT IN (SELECT DISTINCT subscriber_email FROM table_one)

There are about 4600 rows in table one, and 145,000 rows in table two. Does this seem like it would be a burdensome query?

I'm not a SQL expert my any means, so is there a better way to go about this? It seemed like a simple one to me. Maybe my web host is just stingy with the CPU time.

Nested SELECT Statements
I try to figure out how to use a nested "SELECT" statement after the
"IN" predicate. For example, when I try this code, it doesn't return
anything although it should:

SELECT book.IDLivre, aut.Prenom, aut.Nom FROM livre book, livreEcritPar
ecr, auteur aut WHERE ecr.IDLivre = book.IDLivre AND aut.IDAuteur =
ecr.IDAuteur AND book.IDLivre IN ("SELECT book.IDLivre FROM livre book,
livreEcritPar ecr, auteur aut WHERE aut.Prenom like '%$firstName%' AND
aut.Nom like '%$name%' AND ecr.IDAuteur = aut.IDAuteur AND book.IDLivre
= ecr.IDLivre");

So, my question is the following: How should I change syntax in order
to make this bunch of code work? I mean, under Oracle SQL, this syntax
would be legal and work perfectly, so I'm confused how to solve my
problem.

Nested SELECT Statements
I am trying to form a query from a search form where users can search by various catergories. The version of MySQL I am using is 4.0.18 and doesn't seem to support nested select statements since it returns a syntax error at the point I try to use one. I can't use temporary tables or views as there are no permissions for create at the php page level. I really don't know what else to try as my SQL knowledge is not that vast. The query I have built so far is:

SELECT DISTINCT clientid, name
FROM (SELECT tbl_clientdetails.* , id, date_made from tbl_clientdetails, contact_made
WHERE tbl_clientdetails.clientid = contact_made.clientid) AS t1
WHERE id <> any (SELECT id from contact_made where date_sub(curdate(), interval 90 day)<= date_made)
AND name like '%boat%' OR industryType like '%boat%' OR comments like '%boat%' OR productBrand like '%boat%'

Nested SELECT Statements
I am trying to form a query from a search form where users can search by various catergories. The version of MySQL I am using is 4.0.18 and doesn't seem to support nested select statements since it returns a syntax error at the point I try to use one. I can't use temporary tables or views as there are no permissions for create at the php page level. I really don't know what else to try as my SQL knowledge is not that vast. The query I have built so far is:

SELECT DISTINCT clientid, name
FROM (SELECT tbl_clientdetails.* , id, date_made from tbl_clientdetails, contact_made
WHERE tbl_clientdetails.clientid = contact_made.clientid) AS t1
WHERE id <> any (SELECT id from contact_made where date_sub(curdate(), interval 90 day)<= date_made)
AND name like '%boat%' OR industryType like '%boat%' OR comments like '%boat%' OR productBrand like '%boat%'

Syntax Error With Nested SELECT
Working with MySQL 4.0.27-standard via phpMyAdmin (and Perl)

I've been getting error #1064 for certain SQL statments, and have traced the problem down to nested SELECTs.

This works fine:

SELECT `CITY` FROM `pa_geotags` WHERE `PLACE_ID` = 1303 ;

Whereas this (just a trivial example to show the point):

SELECT `CITY` FROM `pa_geotags` WHERE `PLACE_ID` = (SELECT 1303) ;

gives rise to:

#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 'SELECT 1303 ) LIMIT 0, 30' at line 1

I've tried several other (more complex) nested SELECTs, all give exactly the same type of error. phpMyAdmin seems to be non-optionally adding 'LIMIT 0, 30' to the end of my SQL before submitting it, but I don't think that's the problem; I sent the same SQL to the same database via a PERL script and also got a syntax error reported.

Insert With Nested Select Problem
I want to implement a query similar to this in mysql:

insert into table1 (field1)
(select t2.field2
from table2 t2
where t2.field3="string" and t2.field4=table1.field4)

the reference to table1 from the inner query (table1.field4) does not work.

Is there a way to achieve this?

Nested Sets And Filtering Conversion To Nested Arrays, How?
I am currently working on a project where we want to reuse a tree structure stored in the database. The tree are basically groups/categories of all the content available within the project. Now we want to reuse this data in forum and only show the featured items/nodes.

An idea of the tree structure is:

+ root
+ Music (f)
+ Genre
- Electronic (f)
- Classical (f)
Now the problem is that we don't wan to show the whole tree structure within this new forum. But only the ones for example, which are flagged to be featured. For this, we have a field in the groups table. Only I happen to have some problems with reusing this tree hierarchy:

The main problem I have is that when I get the whole tree structure using the query SELECT * groups ORDER BY left_id then I have the whole tree.

Only when I add "WHERE featured=1" then the left and right node values are becoming invalid because I filtered out possible child or parent nodes.

I am curious if anyone could help me how to get the structure in such way I can easily reuse it. I would love to have the featured nodes in a nested array. Something like:

root
children: music
children: electronic, classical etc.

Combining SELECT Statements Into One SELECT Statement.
I want to take the results from:

SELECT name.empnumber, name.firstname, name.lastname
FROM name INNER JOIN authuser
ON name.empnumber = authuser.uname AND authuser.team = 'PHQ'
ORDER BY name.lastname, name.firstname;


and the results from:

SELECT name.empnumber, name.firstname, name.lastname
FROM name INNER JOIN crew_attendance_6QJ
ON name.empnumber = crew_attendance_6QJ.empno
ORDER BY name.lastname, name.firstname;


And combine them into one query that outputs all of the results both queries would output. Then order those results.

So far I have come up with:

Insert Multiple Rows With One Insert Stmt And Nested Select
I'm trying to insert several rows into a table using only one insert statement:

insert into component_feature values (select 3,1,sf.software_feature_id,1 from software_feature sf where sf.software_id = 1)

When I run the select statement alone, I get the result I want:

+---+---+---------------------+---+
| 3 | 1 | software_feature_id | 1 |
+---+---+---------------------+---+
| 3 | 1 | 0 | 1 |
| 3 | 1 | 1 | 1 |
| 3 | 1 | 2 | 1 |
+---+---+---------------------+---+

But when I run the complete statement I get:

ERROR 1064 (42000): 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 'select 3,1,sf.software_feature_id,1 from software_feature sf where sf.software_i' at line 1

This query is part of a PHP application I'm building. I'd rather not have to write a PHP loop to do multiple inserts.

Help Me With This Select Statement :)
I have two tables
1- articles table which contains the articleid and article_description
2- articles_translation table which contains translation_id, article_id(foreign key from the articles table) and translation_description

I would like to select all the articles which aren't translated yet... How can i do this in MySQL?



Is There Something Like A SELECT ALL BUT Statement?
Usually the tables I have to handel have a high number of columns. Additionally, columns are deleted and added dynamically. Most calls made on these tables are select statements:

Consider two tables t1 and t2. A natural join results in the columns a,b,c,d,e,f,g,h,z. A usual select statement is the following:

SELECT a,b,c,d,e,f,g,SUM(z) FROM t1 NATURAL JOIN t2 GROUP BY a,b,c,d,e,f,g

This way the column h could be "eliminated". As you can see the select and the group by clause can become fairly long. What I am looking for is a clever way to say "Group by everything but h and z". Is that possible?

Need Help With SELECT Statement
I have 2 simple tables: emps and rprts.
Table emps has: "ID", "name" (simple string), and some other irrelevant fields.
Table rprts has: "ID", "emp_id" (indication of "ID" in emps table), "rprt" (10-digits time), and "type" (boolean).

I want to select the fields "ID" and "name" from emps, and in addition - for every selected row I want to select rprts's "type", where "rprt" (or "id", doesn't matter) value in the highest.

For example:
emps:
id name
------------------
1 jeff
2 wanda
3 brad

rprts:
id emp_id rprt type
-------------------------------------------
1 3 df 1
2 1 ie 1
3 2 ei 1
4 3 fd 0
5 2 tg 0
6 3 gf 1
For this data, the following should be selected:

id name type
----------------------------
1 jeff 1
2 wanda 0
3 brad 1

I tried several things, but I want to keep it simple and readable, so I'll understand if I'll read it sometime in the future.

Select Statement
SELECT *
FROM Distance, LorryDetails
WHERE cavan = (Select min (cavan) From Distance where cavan>0);

here is the results i am getting

source ,Cavan, Athlone, Cork, Galway ,LorryID, LorryReg, Position
Athlone 90 0 180 80 3 02-CN-8001 Cork
Athlone 90 0 180 80 7 00-CN-1000 Cavan
Athlone 90 0 180 80 10 02-G-8001 Galway
What i want to try and do is compare the Values with the Column names and get the shortest path. for example when you compare the position cort with the column cork it is 180, cavan is 90, and galway is 80. Galway is the nearest to athlone so i want to narrow down the results to just give me back the row where the position is equal to Galway. Can anyone help me with this.

SELECT Statement
I am trying to search a table with a statement like the following;

"SELECT name FROM table WHERE state='$state' AND trigger=1 AND areaA='$area' OR areaB = '$area'";

The problem is I need it to find the 'area' value in one of two different colums while matching the 'state' and 'trigger'. My syntax seems to be incorrect and I dont know how to find matching for 2 values while the other 2 columns can be optional. but one must be found.

Select Statement
I have a transaction table, wich has multiple transactions for one customer. each transaction has type. I want to find all customers who do not have a particular type of transaction.

The problem I have is it seems to find a postive result for every customer because every customer has a least one transaction that is not of this type. and I want the ones who have never had a transaction of this type.

Select Statement
I have a DB with a lot of tables (of course) :-)

In one of these tables I have the following structure (almost) Table "News" - ID, username, pagetitle, content. I also have a "users" table where I have username, fullname and groupname (simplified)

I want to list out how many "posts" every user has done, sorted by group..

Example:

user 1: 226 pages - Testgroup
user 4: 115 pages - Testgroup
user 6: 29 pages - Testgroup
user 2: 1 pages - Testgroup

user 12: 226 pages - Anothergroup
user 7: 115 pages - Anothergroup
user 9: 29 pages - Anothergroup
user 3: 1 pages - Anothergroup

Can anyone give me a hint in howto setup my select statement?

SELECT Statement
I have a single table that I want to select each row and group by one field and order by another. Example:

blogger  |   blog text  |  blog date

jim           blah           11/11/07
anna          blah           11/10/07
chris         blah           11/09/07
chris         blah           11/08/07
jim           blah           11/07/07
anna          blah           11/06/07

I want to group by the blogger and date descending, BUT ALSO sort by which blogger has the newest entry My output should be this:

jim           blah           11/11/07
jim           blah           11/07/07
anna          blah           11/10/07
anna          blah           11/06/07
chris         blah           11/09/07
chris         blah           11/08/07

What is the best way to produce my desired results?

Select Statement!
I have a simple query that is similar to this one:

SELECT distinct b.username from permissions a, users b, links c where
a.user_id = b.id and c.information = 14;

In this case, it selects the all users details from table 'user' that are
permissioned to access a certain information with id = 14.

The problem is that I need to select the users that are not permissioned but
I have sql v3.23 and I canot use union.

In other words, I need to do a select b.username from users b where
b.username not in "the result" of the last select.

SELECT Statement
I have two tables say TableA and TableB. I want to be able to select
a group of entries from TableB but only display the records that meet
the search criteria and are NOT in TableA. For example.

TableA:
111,John,55
112,Joe,13
113,Matt,55
114,Shawn,55
115,Dave,13

TableB:
990,John,12345678
991,Joe,12345678
992,Matt,12345678
993,Shawn,87654321
994,Dave,87654321
995,Steve,12345678
996,Tom,12345678

I want to display a list of people from TableB belonging to group
12345678 who do not already appear in TableA's group 55. The result
should be:

Joe
Steve
Tom

I have had no luck at all finding a solution. I know this would
probably be pretty simple if I were able to nest queries within
queries but the version of MySQL we are using doesn't support this.

Select Statement
--------------------
| ID | CODE |
--------------------
| 1 | A |
--------------------
| 2 | A |
--------------------
| 2 | B |
--------------------

I need to get ID that contains both CODE A & B, (i.e., 2 in the above case), is it possible that I can make do this in a single select statement?

Select Statement
I've got this little SELECT query that's not returning any results. Maybe someone can give me some insight?

my $user = 'abc@emailaddress.com';
my $passwd = "xyz123";

my $sth = $dbh->prepare("SELECT email, password, sub_code FROM userfile WHERE email = '$user' AND password = '$passwd'");
$sth->execute();
my @row = $sth->fetchrow_array;

Else If In Select Statement
i have a bunch of records that i want to pull on the basis of eg

SELECT lat, lng, html, label, icontype FROM ade WHERE icontype='" . $_POST['name'] . "'";

but i'd like to make the first query and also another on an "if else" basis to cover various bases

if i post a query where the 'name' isnt an icontype, i want it to look in the "section" field and pull those records matching a certain value ie all records that have a value of "5"

is it possible to do something like this

SELECT lat, lng, html, label, icontype FROM ade where icontype='" . $_POST['name'] . "' ELSE IF section='" . $_POST['name'] . "' ELSE IF catid='" . $_POST['name'] . "'";

SELECT Statement
I am having trouble returning the correct records. My database structure is as follows:

TABLE1
ID

TABLE2
MEMBER_ID
START_YEAR
END_YEAR

START_YEAR and END_YEAR are stored in TABLE2 as a number, not an actual year.

Two numbers are static 36 and 55. I need to select any records that have a START_YEAR and END_YEAR range between 36 and 55.

Here is my current query but it only returns records with START_YEAR or END_YEAR values between 36 and 55. I would like to return any record that has a value between its START_YEAR and END_YEAR that falls between 36 and 55.

SELECT COUNT(ID) FROM TABLE1
INNER JOIN TABLE2 ON (MEMBER_ID = ID)
WHERE START_YEAR BETWEEN '36 AND '55' OR
END_YEAR BETWEEN '36' AND '55;

The following would not be returned in this quey but needs to be.

START_YEAR = 22
END_YEAR = 56

Select Statement
I have a database with say 2000 records. The key record is numbered 1,2,3...2000, nothing fancy there.

I am using the mySQL database with perl.. basically I want to submit a few queries at the top of the page, and then use the information as I go down the page. The issue that comes up, is on this page I want a weird order of information. Basically I want records with secKey 1, 2, 3, 1566, 4, 5, 6, 7

So my first thought was to do one big select.. something like

$result = mysql_query("SELECT * FROM `db` WHERE secKey<1004 OR secKey=1566 OR secKey<8");

The problem with that.. is I don't think I have a guaranteed order. They HAVE to be in the order I listed before. So my second thought was something like this Code:

SELECT Statement
How can i get MySql to return a string or true or false or whatever if certain column is empty or null

like:

SELECT * FROM a
IF a.columnA = '' THEN a.columnA = 'something' END IF

So i dont need php to evaluate every column returned from mysql

like:

if($row['columnA'] == ''){

echo 'Nothing here';

}else{

echo $row['columnA'];

}

SELECT With IF Statement(?)
# Table structure for table `db_emails`
#

CREATE TABLE `db_emails` (
`id` int(10) NOT NULL auto_increment,
`user_id` int(10) NOT NULL default '0',
`email` varchar(255) NOT NULL default '',
`main` int(1) NOT NULL default '0',
`list` int(2) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

#
# Dumping data for table `db_emails`
#

INSERT INTO `db_emails` VALUES (1, 1, 'a.a@a.se', 1, 1);
INSERT INTO `db_emails` VALUES (2, 1, 'aa.aa@a.se', 0, 2);
INSERT INTO `db_emails` VALUES (3, 2, 'b.b@b.se', 0, 1);
INSERT INTO `db_emails` VALUES (4, 2, 'bb.bb@b.se', 0, 2)

So, now to my question. How can i do a SELECT where i want all email adresses BUT only the main if main=1 and all if main=0. The result for this dataset should be:
a.a@a.se
b.b@b.se
bb.bb@b.se

Select Statement
i am currently using the followin code to query an access db


SELECT * FROM tools WHERE item LIKE '%#item#%' or des LIKE '%#item#%'

item is a var i am passing in

this works fine however what i wanna do is display the results in this order

i want to list the matchs with item first regardless of the order rather then des which is where the item is matched 1st.

Select Statement
I have 2 tables one has the list of clients the other the shipments the client has received.
Table 1 name is client
id
first_name
last_name

Table 2 name is shipment
id
clientid
shipped_date
productid

My question is how do I setup my query to show the last time the client was shipped. I was just doing a group by clientid, but that does not group by last shipped_Date.

SELECT Statement
I want to execute the following statement:

SELECT ID,title,starttime,endtime FROM mytable WHERE starttime >= 32400

This procudes the following error:
You have an error in your SQL syntax; ch
eck the manual that corresponds to your MySQL server version for the right synta
x to use near '>= 32400' at line 1.

starttime is a VARCHAR(10).

Select Statement
when i try the following at the mysql command line...
select * from items;

nothing returns, it just hangs indefinitely. Does anyone know why this is? I have ran "unlock tables"
I have already logged into mysql, all its services are running, and I have selected the right database, but not sure why its not working.


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