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


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Select Based On Two Rows In Mapping Table


I have a many to many relationship between a resource and tag:

resource - 1:M - tagged_resource - M:1 - tag

So a resource can have many tags and a tag can belong to many resources. The data would look like this:

RESOURCE TABLE
id: 1
name: resource1

TAG TABLE
id: 1
tag: new
id: 2
tag: tested

TAGGED_RESOURCE
resourceID: 1
tagID: 1
resourceID: 1
tagID: 2

How can I select the single row from the RESOURCE TABLE which has the tags 'new' and 'tested' in the TAGGED_RESOURCE TABLE?

I have tried using 'IN' but it acts like an OR operator rather than AND.




View Complete Forum Thread with Replies

Related Forum Messages:
How To Delete From 1 Table Some Rows Based On Match Results In 2nd Table?
How to delete from TABLE-1 all rows with indexes "i" that match to index j=2 from TABLE-2?

TABLE 1:
+---+------+
| i | name |
+---+------+
| 1 | item1 |
| 1 | item2 |
| 7 | item3 | <-- delete all rows with i=5,6,7
| 6 | item4 | <-- delete
| 5 | item5 | <-- delete
| 5 | item6 | <-- delete
| 7 | item7 | <-- delete
+---+------+

TABLE 2:
+---+---+------+
| j | i | name |
+---+---+------+
| 1 | 1 | item1 |
| 1 | 3 | item2 |
| 1 | 2 | item3 |
| 2 | 5 | item4 | <---- j=2 => i=5
| 2 | 6 | item5 | <---- j=2 => i=6
| 2 | 7 | item6 | <---- j=2 => i=7
| 3 | 8 | item7 |
+---+---+------+

View Replies !
Updating Rows In Table B Based On Related Field In Table A
Ver 4.1.8-standard for apple-darwin7.6.0 on powerpc (Official MySQL-standard binary)

I am trying to do some data migration based. I have several tables that contain our legacy pkey field and I want to update the tables with new ID's.
I need to do this several times and have tried it several ways to no avail.

Table A
---------
companyID int(10) pKey
legacyID int(10) old legacy pkey

Table B
---------
bAID int(10) pkey
companyID int(10)
legacyID int(10)

Table A has values for both companyID (unique key) and legacyID.
Table B has values for bAID (unique key) and legacyID but companyID is empty.

I need to update tableB.companyID with tableA.companyID based on tableb.cSerialID to tablea.cSerialID relationship.

I need a query that will update ALL rows.

View Replies !
Returning Rows In Left Table Based On Mutliple Criteria In Right
This is starting to get to me. I'm sure there's a simple way of handling what i'm trying to do, but someone might be able to help out quicker than spending another hour searching and testing for this. Here's the problem:
Simplified tables:
ARCADES
=======
ID,
name
GAMES
======
ID,
name
ARCADES_GAMES
=============
ID,
arcade_iD
Games_ID
Straightforward enough so far right? I'm trying to get all arcades that have ALL games in a passed in set of game_id's. So for instance I might want all arcades that have the games 11 and 14, but it must have both those.
I can do soemthing like...

SELECT a.name
FROM arcades a
WHERE EXISTS(SELECT 1 FROM arcades_games
WHERE arcade_id=a.id AND game_id IN (11,14))
But that'll return all rows that match ANY of (11,14) rather than ALL of 11,14.

It all comes down to the simple thing of getting rows in a table where all criteria from a list is met, but any advice on how i would do something like this?

View Replies !
Select Data From 1 Table Based On Criteria From Another Table
is it possible to select all the data in one table based on a criteria from another table?

for instance i want to select all the therapist from massage_therapist WHERE massage_schedule.finish > 0.
i don't want merged results. i just need to list all therapist based on the where criteria from a different table.

these two tables have the therapist_id in common.

View Replies !
Updating A Mapping Table
I have a Publications table and a Themes table. There is also a mapping table for these tables as well.

When I input new records into Publications, my mapping does not get updated. When I delete, then the mapping table will get updated. (This is MySQL 4.x, so no trigger statements.)

My fear is that as I use the mapping table to display some information on a Web page, I will need to update that table "by hand" after I've entered a new record for Publications. Is there some method that I don't know of that will update my mapping table whenever I put in new records into Publications (esp. via a Web form)?

This is the setup for the mapping table: it has foreign keys on the primary key (ID) column of both Publications and Themes. That's it, nothing else in there.

View Replies !
Insert Master_id Value Into The Mapping Table?
I have normalized my database and put in all mapping/lookup tables

How do i inset this master_id value into the mapping table?

Tables =

master_info
This has all the persons information

Qualifications
this holds a list of possible qualification's the person may have

Mapping table
This has
Qual_id and Master_id

qual_id is populated on submit

View Replies !
Graphical Database/table Mapping
is there any application that can graphically map the relationship of tables? or probably create tables with a "graphical" UI? stupid question?

View Replies !
Inserting Values Into A Mapping Table
I am using a mapping table with two primary keys (ID1, ID2). When I try to insert data into this table I get the following error:
Quote:

Violation of PRIMARY KEY constraint 'PK_myTable'. Cannot insert duplicate key in object 'dbo.myTable'. The statement has been terminated.

I am able however to insert values if I do it directly into my table.
Here is an excerpt of my

comm = New SqlCommand( _
"INSERT INTO myTable (ID1, ID2) " & _
"VALUES (@ID1, @ID2)", conn)
' Add command parameters
comm.Parameters.Add("@ID1", System.Data.SqlDbType.Int)
comm.Parameters("@ID1").Value = ID1List.SelectedItem.Value
comm.Parameters.Add("@ID2", System.Data.SqlDbType.Int)
comm.Parameters("@ID2").Value = ID2List.SelectedItem.Value

View Replies !
Use A Mapping Table To Get Query Results From Several Tables
Ok, so I have 4 tables...

Projects -> id, project_name, project_type
Variables -> id, variable_name
Symbols -> id, symbol_name
Mapped -> project_id, variable_id, symbol_id

if I had to find

(project_id=5, variable_id=2, symbol_id=3) AND
(project_id=2, variable_id=14, symbol_id=1) AND
(project_id=34, variable_id=78, symbol_id=44)

How could I write a query that would return the results for these all at once?

I would like project_name, project_type, variable_name and symbol_name returned from their respective tables for each. Is that possible? I've been looking at inner joins and managed to make it work for 2 ids but not 3

View Replies !
Select Rows Not In Second Table
I want to select all records in a "User" table that are not in the "Groups" Table.

Select
users.USERID,
users.NAME
From
users
Outer Join groupmembers ON users.USERID = groupmembers.empid
Where
groupmembers.groupid <> '9'

In therory this would return me all users not in group 9, but I am getting an error in my SQL... I dont really understand Left - Right - and Outer joins but I have tried all three... I could do this in 3 queries - Create a Temp Table - Delete Records w/ 9 in group ID ... Select remaing records.... But there must be a better way...

View Replies !
Select Every 3 Rows From A Table.
I have a bit of a problem, Iam doing a match results page with data from mysql.

My table Name: JuniorMatchResults

Data Colums: id, date, venue, position (1,2 or 3), weight.

What i wanto to do is output this information in my website such as you would have the 1st 3 positions outputted in a table, the the next set of 3 in a table and so on.

View Replies !
Rows Based On First Letter
I'm trying to figure out the fastest/best way to return rows based on the first letter of the title column in my table. For example, I want to get all the article titles that start with the letter "a".
Is there any difference between the two select statements? Any reason to use one over the other? Memory? Speed?

SELECT title FROM table WHERE LEFT(title, 1) ='a';
or
SELECT title FROM table WHERE title like 'a%';

View Replies !
Select Double Rows In One Table In One Query
I try to select double rows in the same table within one query. I can do it with 2 query's but i wonder if it's possible with one?

The table 'admin_category:

Quote:
id name sub
1 cd 0
2 dvd 0
3 action 1
4 new 1
5 general 2

The current query which i use:

PHP Code:

 SELECT a.name AS sub, b.name AS category
FROM admin_category a
LEFT JOIN admin_category b ON a.sub = b.id
WHERE a.id = '4' 

What i try to reach with above query is that row 4 will be selected, take the name of it (new) and also the main category (b.name as category) by doing a left join on the same table where the sub id = the id.

The output of above query is:

sub = new
category = NULL

(Category should be 'cd' but it's not)


View Replies !
Select Rows From One Table Which Not Exists In Antoher
How do I select functions that website with website_id = 1 doesn't have.

The correct answer will be function_id = 4 since functions_to_websites contains function_id = 1 to 3 for website_id = 1

And if I add another row in functions which is not mentioned in functions to websites it should be returned aswell. Code:

View Replies !
Select Rows Where A Field Value Exists In Another Table
I have a table with a column of email addresses I have a second table with a column of email addresses I want to select all the rows in the first table whose email value exists in the second table Can't get a query to do this without an error,

View Replies !
Filtering The Rows Based On Its Timestamp
I'm trying to write a backup script that takes the last modified rows of a table in x days. I can do it if I have a timestamp column for every table in the database, but my aim is to write a script for general use as anyone can use it with his/her database without the need to add that column.

This will be possible if there a property gives the last modified timestamp of a row.

does anybody has any way to reach that target?

View Replies !
Determine The Size Of A Set Of Rows Based On A Where Clause
I have tried looking for a solution to this problem but no luck. The
thing is, in my system, I have a set of users who have a 'quota'
limiting their usage. They can create n number of tables and put m
number of rows in it, but at the end, their 'usage' can not exceed,
lets say, x MB. My problem is, how to I evaluate the space being used,
given the fact that I can pull all data for a user by including a user
ID in the where clause. In other words, I need to find size of the
result set containing all user's rows.

I am using mysql jdbc driver and not sure if there
is any API that deals with the physical size of the resultset.
resultset.getFetchSize() talks in terms of rows v/s the actual space
they take.

View Replies !
Query Which Gets Rows Based On A Radius, Lon And Lat Doesn't Work?
I have found this query which gets rows based on a radius. I need this for zip codes based on lon and lat's.

$sql2 = "SELECT * FROM table as z WHERE (SQRT( (69.1 * (".$userLat." - z.lat)) * (69.1 * (".$userLat." - z.lat)) + (53.0 *(".$userLong." - z.lon)) * (53.0 *(".$userLong." - z.lon))) <= ".$userRadius." )";
return $sql2;
$res = mysql_query($sql2, $connDB) or die(mysql_error());
$row = mysql_fetch_assoc($res);
based on a test zip code gives a result like


SELECT * FROM table as z WHERE (SQRT( (69.1 * (52.399834 - z.lat)) * (69.1 * (52.399834 - z.lat)) + (53.0 *(4.840762 - z.lon)) * (53.0 *(4.840762 - z.lon))) <= 100 )
the lat and lon of the test zip code are right. As you can see z.lat and z.lon don't get any value. And these would be every lat and lon in table.

In my db table lon and lat are decimal(10,6) type with a default value of 0.000000

View Replies !
Adding Missing Rows In Table In 1 Select (+ Join) Command.
Hi all! Here's what I need to do :

I have two tables :
A B
a b c d
---- ----
1 z 1 k
2 x 5 l
3 c 6 j

I need a SELECT with JOIN that would give me :
A
a b
----
1 z
2 x
3 c
5 NULL
6 NULL

so I need to add the missing rows from the A.a and B.c JOIN,
how can I do that ?

I can't use a Union 'cause I can't use MySQL version 4.

View Replies !
Applying A WHERE Clause To Several Rows On A Joined Table To Select A Single Row
I have one table which is users for example

id | username

and another table called ratings for example

user_id | title | rating

and I want to select users who have rated more than one thing... I can do this easily if I want to select users who have rated just one title using the following query

SQL Code:
SELECT * FROM users INNER JOIN ratings ON users.id = ratings.user_id WHERE ratings.title="blah" GROUP BY users.id

but cannot think of a way to do this for more than one rating. Doing

SQL Code:
SELECT * FROM users INNER JOIN ratings ON users.id = ratings.user_id WHERE ratings.title="blah" AND ratings.title="blahblah" GROUP BY users.id

View Replies !
Selecting Multiple Rows In The Based Column With AND Condition
I am facing a very big headache for a few days. I have looked through the forum for solution but found no satisfactory answer. Essentially my problem is the same as the one found in another thread, hence I use some parts of that thread to illustrate my point. Assuming the following scenario: ...

View Replies !
Select Based On FK
I have two questions regarding the MySQL v4.1.16 scenario below:

1. What should the FK on update and on delete parameters be (i.e., default, cascade, restrict, no action, etc.)?

2. How can I insert the correct id’s as implied below?

I have tried just about everything (including “Insert …select”, “LAST_UPDATE_ID();”, etc.) and whenever I think I am starting to get close I either get more errors or ‘0 records added’ with no error message;

I would greatlyappreciate someone who could instruct me on how to accomplish this task.

View Replies !
SELECT Based On 2 Tables
I'm writing some custom stuff to pull from a WordPress install I have one one of my servers.

For one function I want to SELECT all the rows from one table based on criteria from that table and another table (they are related by the row ID of the first table). Here is the SQL I have now....

sql Code:
Original
- sql Code

SELECT DISTINCT t2.* FROM wp_term_relationships AS t1, wp_posts AS t2 WHERE t1.term_taxonomy_id = '4' AND t2.post_status = 'publish' AND t2.post_type = 'post' ORDER BY t2.post_date DESC

SELECT DISTINCT t2.* FROM wp_term_relationships AS t1, wp_posts AS t2 WHERE t1.term_taxonomy_id = '4' AND t2.post_status = 'publish' AND t2.post_type = 'post' ORDER BY t2.post_date DESC

It seems to be returning too many results. It's just returning all the rows from wp_posts that match the post_type and post_status criteria and ignoring the term_taxonomy_id (from wp_term_relationships) requirement.

View Replies !
Select Based On Rarity?
I have a table and one column is titled "rarity." Every once in a while, ONE random row from this table will need to be selected... I want to select the random row based on the rarity column. All of the rarities would equal 1. For example, a rarity of .38 would have .38 probability of being selected from the table.

View Replies !
SELECT Based On All Day Names And Their Hours
I have a table which has a DATETIME column which stores datatime for each record.

I wanted to calculate the total/average of the records for each day and then for each hour of that day ALL TIMES like not only the current week or current month or year but for all available records.

a sample output can be

Monday
00 (count value)
01 (count value)
02..... (count value)
23 (count value)

Tuesday
00 (count value)
01 (count value)
02..... (count value)
23 (count value)

...

Sunday
00 (count value)
01 (count value)
02..... (count value)
23 (count value)

I tried something like following

SELECT count(id) as cnt,HOUR(hitdate) as hr, hitdate FROM hits GROUP BY DAYOFWEEK(hitdate),HOUR(hitdate)

And I am getting the following results, (long result)

cnt hr hitdate
1274 0 2008-07-27 00:00:50
1235 1 2008-07-27 01:00:07
921 2 2008-07-27 02:02:13
830 3 2008-07-27 03:00:03
674 4 2008-07-27 04:02:49
617 5 2008-07-27 05:00:37
606 6 2008-07-27 06:01:41
545 7 2008-07-27 07:01:52
534 8 2008-07-27 08:05:58
630 9 2008-07-27 09:04:01
680 10 2008-07-27 10:04:41
688 11 2008-07-27 11:01:26
881 12 2008-07-27 12:00:22
745 13 2008-07-27 13:00:09....

View Replies !
Select Columns Based On Subselect
Is it possible to do the following:

select (select from factors where type='factor_1') from survey_results where last_name='some_name';

I get the error: "#1242 - Subquery returns more than 1 row"

Can I convert the rows to a list?

More info if needed:

I have two tables, 'factors' and 'survey_results'. A survey_result row contains a list of factors (> 30). Factors can have different types. For a survey result I'd like to select only the columns related to a certain type of factor and analyze just those factors (e.g., find the min and max scores). I don't want to hard code lists of factors of certain types to use in my outside select statement. I'd like to do it dynamically based on the factors table.

View Replies !
Select Statement Based On Bytes
I have a table with an attribute named "message" with a varbinary type in which information is being stored in. It contains a total of 10 bytes and I want to select ONLY bytes 4-7.

View Replies !
Mysql Select Based On Datetime
I am having an issue returning a known record based on a date field that is of datetime format from mysql.

the data looks like this in mysql: 2006-01-26 20:01:45
here is the eror I receive:
SQL error=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 &#3920;:01:45' at line 1

this is the select statement I am using

("SELECT selections from your_show WHERE userid = $userid and date = ".rawurldecode($date)." ");
$date is passed as 2006-01-26%2020:01:45


View Replies !
Selecting Data Form One Table That Is Based On An Entry In Another Table
This is the code I am using:

***********
SELECT co_name,city,country,logo_small FROM $info WHERE $info.co_name=$categories.co_name AND WHERE $categories.everyday_wear='y' ORDER BY co_name ASC
***********

I am using a while loop in php to loop through all of the records but no records are being displayed. What am I missing? Do I need to use a JOIN statement?

View Replies !
Conditional Select Based On Query Results
I want to print a different message on the database, if a query returns an empty set and a different if the query returns any records. How can i accomplish that? I looked at the case statement but i can't get it working with that.

View Replies !
Select And Return Based On The Relation Of Two Other Tables
I'm learning mysql and am looking for an example of how to do a certain type of search.

I have three tables and I'd like to pull records from one and order them based on the relation of two tables. My tables are: ....

View Replies !
Select Record Based On 'change' Date
I currently have a database containing a table with the following fields:
signid, sign_typ, changedate and time.

The 'changedate' field is the date on which the star sign changes and becomes 'active' until the next 'changedate' in the table. I am trying to search this field by a date the user enters and display the 'sign_typ'.

View Replies !
Updating Table Based Upon Matching Field In Second Table
I have a database of books that was originally created as a flat file.
Each record has a number of fields, including the authors name. I'm
trying to convert the database to something a little more efficient.
I've created a new table (called Authors) of unique authors names and
assigned each one a unique ID. I've added a new field in the original
table (called Books) for the author's ID. Now, I need to update the
original table with the author ID from the Author's table.

Something like this:

UPDATE Books SET AuthorID = Authors.AuthorID WHERE AuthorName =
Authors.AuthorName

This obviously doesn't work. Any assistance on how to forumulate this
query (or, if I'm headed down the wrong path, the correct way to do this
operation) greatly appreciated.

View Replies !
How Do I Generate Results Based On Totals Of Another Table But For 1st Table?
This is what I want to do:

1- I have Two tables: polls_created and votes

2- Table polls_created is like:

poll_id
owner
poll_subject

3- Table votes has the votes issued for a given poll, like this:

vote_id
poll_id
vote
vote_date

So what I need to do is to look at these 2 Tables and generate results based on values of these 2 tables.

How do I then generate this result:

MySQL Code:
SELECT poll_id, owner, poll_subject, COUNT(vote_id) AS number_of_votes FROM polls_created, votes
"sorted by polls that have gotten most number of Votes"

Of course "sorted by polls that have gotten most number of Votes" is not real MySQL

View Replies !
CREATE Tablename Based On Result Of SELECT Statement?
Is it possible to have an CREATE statement that contains a SELECT in the section of the CREATE that specifies the TABLE?

I want to have a sql script that can execute SELECT YEAR(CURDATE()) and SELECT MONTH(CURDATE()) to give me the Year and Month and then use these to create the Table Name: tbl_MetaData_2008-03

Example:

CREATE TABLE tbl_MetaData_X-Y
( ...

Where X is the YEAR and Y is the MONTH

View Replies !
Update Table Based On Email In Another Table
I'm having trouble updating the entries from a table. The situation is as follows:

Customer table contains:
1) customer_email_address
2) customer_newsletter (value 0 or 1)

Visitor table contains:
1) email

The visitor table contains email addresses from customers that have signed up through another system.

I would like to update the customer table and set customer_newsletter to 1 where customer_email_address matches email from the visitor table.

View Replies !
Selecting From A Table Based On Info In Another Table
Essentially this is what i want to do. I have two Tables,

Table A- has the field "id" which is the primary key
Table B- has the field "id" which is the primary key


Select * from tableA where Table A.id is not in tableB.id


How can i form a statement that will accomplish the above.

View Replies !
SELECT Rows With Field Different From Previous Rows
I have a table (sens_samples) with mysqlerature sensor samples taken every 5 minutes. Rows are: id (INT), sensor_id (INT), timestamp (DATETIME), mysql(FLOAT) and over_mysql(BOOL).

I want to make a query to get ONLY the rows when over_mysql field changed from "previous" row value. I know that database rows are UNORDERED, but ORDER BY can "place" them in a given order.

My query may be "syntactically" something like: SELECT timestamp, mysql FROM sens_samples WHERE "PREV_ROW".over_mysql <> over_mysql AND sens_id = 1 ORDER BY id;

How can I get it using MySQL?

View Replies !
UPDATE Based On Value In Another Table
How do I update a table to remove orphaned references to a second table? I've deleted rows in the second table, which has a unique auto_increment key. The first table now has references to keys that no longer exist. I need to update the first table, setting the value to NULL where the referenced key no longer exists. Something like:

UPDATE table1 SET table2ID = NULL WHERE table1.table2ID NOT FOUND IN
table2.ID;

The NOT FOUND IN isn't SQL, of course, but I'm not sure what should go there.

View Replies !
Update Based On Another Table
Is it possible to do an update in MYSQL based on another table? I have version 3.23 and when I try to run this statement:


UPDATE ApplicationTbl
INNER JOIN AcademicTbl
ON ApplicationTbl.CampusID = AcademicTbl.CampusID
AND ApplicationTbl.Application_Period = AcademicTbl.Application_Period
SET ApplicationTbl.App_Status = 'Qualified'
WHERE AcademicTbl.Sem_OnCampus >= '1'
AND AcademicTbl.GPA >= '2.4'
AND AcademicTbl.Judicial_Sanction IS NULL

It keeps saying its wrong. Even though I know its not

View Replies !
Selecting From One Table Based On Another?
I have a table for products

and another table for the type of product it is like this:

I need this is be in a seperate table because one product can be several different types like ring,band,wedding,three-stone,etc.

but how can I then select a product based on criteria from the types table

say I wanted to select all products that are type = "Band" and type != "Fancy" ?

View Replies !
Table Based On Info In Another Table
Essentially this is what i want to do. I have two Tables,

Table A- has the field "id" which is the primary key
Table B- has the field "id" which is the primary key


Select * from tableA where Table A.id is not in tableB.id

How can i form a statement that will accomplish the above.

View Replies !
Updating A Table Based On The Value In Another Table In Ver 3.23.54-Max
I am trying to update fields in table SOLAR_SYSTEM based on the values in RESEARCH_LEVEL table

This is a SQL that I am trying to use

UPDATE SOLAR_SYSTEM JOIN RESEARCH_LEVEL ON SOLAR_SYSTEM.USER_ID=RESEARCH_LEVEL.USER_ID SET
SOLAR_SYSTEM.CASH_METAL=SOLAR_SYSTEM.CASH_METAL+1000,
SOLAR_SYSTEM.CASH_CRISTAL=SOLAR_SYSTEM.CASH_CRISTAL+1000,
SOLAR_SYSTEM.CASH_ENERGY=SOLAR_SYSTEM.CASH_ENERGY+1000
WHERE RESEARCH_LEVEL.TYPE='M' AND RESEARCH_LEVEL.LEVEL=1;

I got error

"ERROR 1064: You have an error in your SQL syntax near 'JOIN RESEARCH_LEVEL ON SO
LAR_SYSTEM.USER_ID=RESEARCH_LEVEL.USER_ID SET
SOLAR_SY' at line 1"

I don't know what is wrong. Can I do such an update in Ver 3.23.54-Max in the first place ? IF yes, then what's wrong with my statement?

View Replies !
Creating New Table Based On Old Table
I have a MySQL database with a user table will lots of DUPLICATE email.

I want to delete the rows completely having the duplicate email.

I found a way out is to use some thing like this:

Code:
insert into newtable (email)
select distinct email from oldtable
But this way, only the email column is populated in the new table. I want all the other columns as well.

View Replies !
Join Table Based On Specified Condition
Is it possible to join two tables based on the specified condition in MySQL. For example, i have two tables t1,t2 and t3. The table t1 and t2 has field called name and the table t3 has field name class. I want to select the names from t1 or t2 based on the condition of class(t3). If class=4 then select name from t1, if class=10 then select name from t2.tell the query in mysql.

View Replies !
Deleting From A Table Based On Record Id
I need to execute the following query:

delete from history where id=(select min(id) from history where user = username);

this query doesn't work and gives me an error "ERROR 1093 (HY000): You can't specify target table 'history' for update in FROM clause"

How do I rewrite this query? Ofcourse I can go for two queries, but I'd prefer to do it with a single query.

View Replies !
Order By Based On Results From Another Table
I have a query that , and i need to order the result based on wheter or not the ID of my main table appears on another table, somewhat like this:

SELECT A.id AS Id, A.nome AS Nome
FROM main_table A
JOIN joined_table JT ON JT.id = A.id_cat
ORDER BY ("first whoever have a row in" another_table AT)

another_table stores the image paths related to main_table , i need to show all query results from main_table even if they don't have a image (row in another_table), but i need to show whoever have a image (a row in another_table) first...

I've tryied to join with another_table and even to use sobqueryes in ORDER B... but so far i got no results. it's even worst because this query is a monter with multiple lines (the sample is simplyfied...)

View Replies !

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