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.





Update Column Data Based On Another Table


I've got 2 tables: 'city' that list over 2000000 rows and 'profile' where each row are associated to a city.

What I want to do is to update cities popularities based on profile without having to scan the hole 2000000 rows of 'city'.

So is it possible to make those 2 query in one so I do not need to do a php loop:

SELECT city, COUNT(city) FROM profile GROUP BY city;

then

UPDATE city SET popularity = COUNT(city) WHERE city.city_id = profile.city




View Complete Forum Thread with Replies

Related Forum Messages:
How Do I Replace Data In An Existing Table - Based On A Column With An Identifier
Each record in the table I want to update has a unique identifier: products_model. For a given model number, I want to replace its image, which is located in a field called products_image.

The file with the new data is a .txt file, a sample of which looks like this:

v_products_modelv_products_imageEOREOR
5361453614.jpgEOREOR
5361553615.jpgEOREOR
5372453724.jpgEOREOR

The beginning part of the table looks like this:
+----------------------------------+---------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------------------------+---------------+------+-----+---------------------+----------------+
| products_id | int(11) | NO | PRI | NULL auto_increment |
| products_type | int(11) | NO | | 1 | |
| products_quantity | float | NO | | 0 | |
| products_model | varchar(32) | YES | MUL | NULL | |
| products_image | varchar(64) | YES | | NULL | |
| products_price | decimal(15,4) | NO | | 0.0000 | |
| products_virtual | tinyint(1) | NO | | 0 | |

From what I've read over the past few days...I think I need to:
(a) delete the EOREOR column from the text file;
(b) use the LOAD DATA INFILE command somehow, telling it to ignore the first line of column headers in the text file.

View Replies !
Update One Column Based On Another
I have two tables. One set up like this:

id item_id group_id userid outcome settled

The second is

userid yes no

I would like to look at the first table and find all rows that have a specific group_id, then update the userid yes/no based on the outcome on that row. Outcome Y then add 1 to the yes column of that userid, outcome N then add 1 to the no column of the userid. Is this possible in one SQL statement?

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 !
Update Based On Row Offset From Begining Of Table?
Is there a way to update a table row based on its offset from the begining of the table. I want to be able to update based on a rows position when its brought up when all rows in a table are selected. ie; select * from table.

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 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 !
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 !
Determining Which Table To Query Based On Data Within Tables
I have 2 tables:

default_categories
column 1: category_id
column 2: category_name
column 3: category_parent

custom_categories
column 1: custom_cat_id
column 2: custom_cat_name
column 3: custom_cat_parent

The custom_categories table won't necessarily have anything in it but if it does, I need to choose the data from the custom_categories table over the data from the default_categories table.

So if the default category has 3 rows with IDs | names:
123 | Dogs
456 | Cats
789 | Fish

And the custom category has 1 row with IDs | names:
456 | Very Cute Cats

I want my query of these 2 tables to produce the following IDs | names:
123 | Dogs
456 | Very Cute Cats
789 | Fish

I've tried joins like the one below but they aren't working because if there is no custom_cat_id, it won't give me the result for the default category_id.


MySQL
SELECT *
        FROM default_categories
        LEFT JOIN custom_categories ON category_id = custom_cat_id
        WHERE category_parent = ''
        AND custom_cat_parent = ''
        ORDER BY $order_by $sort




View Replies !
Update Using Like Wildcard And Table Column
I'm trying to update table 1 with data from table 2 where the data in table 1 is like the data in table 2. I need to use the % wildcard but I can't seem to get it to work using a column name. Is this possible, or am I going about this the wrong way. Here is the statement I have, it only updates records that match exactly.

update crowley_preowned,models set crowley_preowned.po_display_model = models.model where crowley_preowned.po_model like models.model

po_models contains say PT CRUISER LXI, models.model contains PT CRUISER. I want to update po_display_models with PT Cruiser from model for any record that starts with PT Cruiser.

View Replies !
Using Table A Column Row Data For Table B Column Headings
Is it possible to add column data in table A and have (dynamically linked) table B column headers?

View Replies !
Select One Column From A Table That Matches Data From Other Table
how to select data from one column in a table where that data maches some other data in some other table, but that data in that other table contains only first 4 simbols of data in my initial table!

T1
aaa
bbb
ccc
ttt

T2
a
b
t

result should be
T1+T2 = T3

T3
aaa
bbb
ttt

View Replies !
Update One Col From Another Col Based On Primary Key
I have a table which stores referral URLs in column 'ref' and primary key of the table is 'clid' I have added another column which will store the name of the search engine referral by the name 'SearchEngine'. Now what I want to do is to avoid PHP processing and write a mysql query as follow,

Code:

UPDATE clicks
SET SearchEngine=(
SELECT (
CASE WHEN (LOCATE('.google.',ref)!=0) THEN 'Google'
WHEN (LOCATE('.yahoo.',ref)!=0) THEN 'Yahoo'
WHEN (LOCATE('.msn.',ref)!=0) THEN 'Microsoft'
WHEN (LOCATE('.microsoft.',ref)!=0) THEN 'Microsoft')
WHEN (LOCATE('.live.',ref)!=0) THEN 'Microsoft')
ELSE 'Others' END
),
@tmpo:=clid
FROM clicks WHERE ref!=''
)
WHERE (clid=@tmpo);

but it gives me following error,

Code:

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 ') WHEN (LOCATE('.live.',ref)!=0) THEN 'Microsoft') ELSE 'Others' END),clid:=@tm' at line 1

Basically i want to parse referral url, decide the search engine name and then store its name in the new column based on primary key so that correct values are stored in correct record.

View Replies !
Insert Data If It's Not In The Table, Otherwise Update
Insert the data if its not in table else if it is there update it How do I do this in MySQL 4?

View Replies !
Update Whole Table With Unique Data Per Row
This is my first post and I am fairly new to MySQL and PHP. I need to update an entire column of data with a column of data from another table. Each row is a price attached to a specific product.

When I do an Update/Select, I get an error saying more than one row is being returned.

Is there a way to do this using MYSQL alone, or do I need to use PHP and and a loop with individual inserts per row?

View Replies !
Update Statement :: Data From One Table To Other
I have two tables, and I want to take data from one table, and overwrite it onto the second. Unfortunately, my SQL is pretty weak.

The first table has a mediumtext column and a id (primary key) column. The second has an id (the same as the first), a number, and a mediumtext column.

I want to take the contents of the mediumtext field with the highest number and replace the contents of the field in the first column with it with the same id.

My instinct is to do it this way:

update forum1post p
set p.pagetext = (select query1.message
from (select pe.message, max(pe.editnum)
from forum1post_edits pe
group by p.postid) query1)
where p.pagetext = 'Why did you all flame my topic. Screw your ****ing forums.'
and p.postid = pe.postid

However, that does not work, as pe is not recognized.

View Replies !
UPDATE Query With Getting Data From Another Table?
is it possible to use UPDATE command with getting data from another table.

I have two tables:
base1.table1 with COUNTRY_NAME, ID_NUMBER
base2.table2 with COUNTRY_NAME, LINK

I need to get value of ID_NUMBER from base1.table1 (about 300 rows) and UPDATE base2.table2. So, I need to copy values of ID_NUMBER to LINK.

I wonder is it possible to do just with one query or I will need to write PHP parser to do this job?

View Replies !
Update One Table With Data From Another That Has Multiple Returns
I have a query that works but it takes extraordinary amounts of time to run and I'm sure there's got to be a better way. I haven't touched sql in many years and I just can't remember the proper way to do this.

Table 1 has a column that I need to fill from table 2. Table 2 has multiples of the requested data. There are about 303 records in table2 that meet the >0 criteria but only 44 distinct values that I need to retrieve. col1 in both tables is the matching index.

What I have so far is:

update table1 a set a.col2 = (select b.col2 from table2 b where a.col1=b.col1 and b.col2>0 group by b.col1)

I also tried limit 1 instead of group by but there was no difference in execution time (which is about 5 updates in 10 minutes!)

View Replies !
Increment Based On Another Column
I'm having a little trouble working out the best way of doing something.

I'm storing a key split across two fields, the first field is 3 letters, the second is three numbers:
CREATE TABLE table1 (
id_a CHAR(3) NOT NULL,
id_b SMALLINT(3) NOT NULL,
...
);
What I'd like to do is have it so that when a new row is entered 'id_b' is calculated as MAX(id_b) + 1 WHERE id_a = new_id_a.

Is it safe to do this as some sort of nested query or is there a better way?

View Replies !
Selecting Another Column Based On Max()
I've got a funky query I'm trying to set up. I've got this poll answers database, and each row has a qid that matches to a question. So I can group answers by the question they correspond to. Now I'm trying to select the total votes and the answer with the most votes for each question. The total votes part is working fine, but I'm having trouble with the winning answer part.

I've got a MAX(votes) that works well, and finds the answer with the most votes for every question, and returns its votes. What I want to do is select the `answer` column (the one that houses the actual text answer) of the answer with the greatest votes (the winner). Code:

View Replies !
Adding New Column In A Table With Data From Another
I have been trying to accomplish the following aince quite some time.. I have tried various combinations of Union, Merge, Insert.Select, etc..

Tables:
table_1 with 22 data columns, and a autoincrement primary key column.
table_2 with 1 column (newtimenumber in query below) with double values, no primary key. (Although i can generate it)

Relation between tables:
The number of rows in both the tables are same, and if required can be mapped on one to one basis. (Not yet done as i have not assigned primary keys to the table_2; but row 1 of table_1 corresponds to row 1 of table_2)

The table_2 is generated by performing a set of calculations on one of the columns in table_1; hence they correspond to each other.

Problem:
I want to insert the all the rows in table_2 into a new Column (newtimenumber in query below) in table_1; but maintaining the corresponding row by row relation.

Tried Insert..select :
INSERT INTO dbname.table_1 (newtimenumber) SELECT swapper.newtimenumber FROM dbname.table_2

this did not work, and generated new column in table_1 but the rows were appended at the end.

I would be very glad if some one could help me with this. I have tried many things, but i am not getting something right.

View Replies !
Import Update Of Csv/excel Data Into MySQL Table
I need to import some data from csv or excel files in my customers table so that for each customer ID it will update an existing field.

My tools for accessing the database on the server is phpMyAdmin, but I could of course also copy the database down, manipulate on the PC, and then re-upload the entire manipulated database.

View Replies !
Data Insertion/Update Form Different Tables Into On Table
I have 3 tables say Employees, Benefits, Employee_Benefit_Mapping. These tables are something like this:

Employee:
========
Employee_Id
Name
Dept_Id
.
.

Benefits:
=========
Benefit_Id
Benefit Name
.
.

Employee_Benefit_Mapping:
=========================
Mapping_Id
Employee_Id
Benefit_Id

Its a many to many relation. Hence the mapping table.

Now the situation and question is:
====================================
Every employee "In a certain Dept" is eligible for some benefits by default. How can add these records with one (or minimum) insert statement(s) rather than going employee by employee?

Insert into Employee_Benefit_Mapping ((Select Employee_Id from Employee where Dept_Id = xx), (Select Benefits_Id from Benefits where Benefit_Id in(xx, yy)))

Will this work to insert all the data into the mapping table?

View Replies !
Selecting Based On Matched Column?
Lets say I have table with two columns zip_work and zip_home. I'd like to construct a query looking something like this:

SELECT {here is the problem} FROM myTable WHERE zip_home=99999 OR zip_work=99999 GROUP BY zip_home, zip_work LIMIT 100;

In response I'd like get two column table with zipcode as the first column and COUNT() of matched users. The idea is to know how many users are working or living in 99999 zipcode.

View Replies !
Selecting Values Based On Column
I couldn'y find solution to this on forum so here it is :

sample table :

id | name | value
1 | x | y
1 | z | v
2 | x | y

i would like to select id where x=y and z=v.

so in this case result should be : 1

(2 is not in the result coz it doesnt match x=y).

How to create such a query?

View Replies !
Auto Increment Based On A Column Value?
I did a bit of searching but couldn't find anything, so:

If I have a table structure similar to this:

Code:
table: productImages

idfilenameproductIdorder

110234.jpg121
213702.jpg122
323674.jpg123
498373.jpg151
544126.jpg152
Would it be possible to create an auto increment value in the 'order' column, based on the 'productId' column?

As an example, if I insert another record with filename = 12345.jpg and productId = 12, then it would set order = 4 based on the previous three entries for that product?

View Replies !
Update A Table With Data From Another Table
I have two tables with similar data. The firs table contains data that is to be updated with data from the second table. The first table (tblA) has a unique key, but the second table (tblB) does not.

I have to use the 'lastname', 'firstname' and 'dept' fields that are in both tables and join the tables on those three fields.

I have tried:

update tblA, tblB
set tblA.empPty=tblB.empPty
where ((tblA.empLName=tblB.empLName)
and (tblA.empFName=tblB.empFName)
and (tblA.empDept=tblB.empDept));

with some test data where I know I have a match using the three fields, but nothing gets updated.

View Replies !
Column That Calculates Average Based On Other Columns?
is it possible to have a column called "average" that adds up and then averages out the data in other columns?

I've got a database with several columns of scores. I'd like to have a column that holds the average score. Then on my website, my visitors can sort by the highest score and I'll be able to pull the info straight from the db..

furthermore, only certain columns hold scores, they're named like "scoreA", "scoreB" and so on...

is this at all possible?

If not, can anyone point me to some php resources that will allow me to calculate hundreds, perhaps thousands of scores (on the fly) and present them from high to low (or low to high)?

View Replies !
How To Insert A Calculated Value Based On Diff Column
let's say I have 3 columns
create table test1 (
id int,
dateCreated timestamp default current_timestamp,
localDateCreated datetime);

the localDateCreated is always 8 hours ahead dateCreated.

so when i insert id number, lacalDateCreated will be calculated based on dateCreated. How to do that?

I thought trigger might help, but it gave error

mysql> delimiter |
mysql> create trigger trgtest2ai after insert on test2
-> for each row begin
-> update test2 set local=new.ts where id=last_insert_id();
-> end;
-> |
Query OK, 0 rows affected (0.03 sec)

mysql> insert into test2 set id=10;
-> |
ERROR 1442 (HY000): Can't update table 'test2' in stored function/trigger because it is already used by statement which invoked this stored fun
ction/trigger.
mysql> delimiter ;

View Replies !
Restrict User Permissions Based On Column Value
I have a client who wants me to make a web database engine for a softball organization (many teams).

he wants him to have administrator rights, and the coaches the ability to update only their roster. The catch is as the players mature and get older their profile will need to move to the next coach. For display purposes (using PHP) I will be doing something like ... "WHERE `team` = '14U'". I want to set it up so only coaches may update their profile if `team` = "14U"

is this possible to do within one table? I have PHPmyAdmin so it should be very easy to checkmark permisions on/off.

An aside, but I will be doing the database administration via phpmyadmin & via MS Access, which I am almost positive shall work, I believe I've done this before.

View Replies !
Join Or Combine Two Tables Based On Unique Column
I use MySQL query browser and have made two tables in one database:

First table: Test
Column names: Filename (Varchar(255)),RowNumber(Integer),Bestandsnaam (Varchar(255)), Pad (Varchar(255)), Grootte (Varchar(255)), Created (Varchar(255)), Modified (Varchar(255)), Accessed (Varchar(255)), Deleted (Varchar(255))

Second table: Hashtest
Column names: Filename (Varchar(255)), RowNumber (Integer), MD5 (Varchar(255)), SHA1 (Varchar(255)), Pad (Varchar(255))

Of both tables the column RowNumber is the primary key. Also, in both tables the column Pad is the same (the same content, not exactly in the same order)

Now, I want to combine the two tables into one table, based on 'Pad'

I suppose I have to use the Script function of MySQL query browser. Please explain to me what I have to do to combine the two tables into one table. This third table has this columns:

Filename (Varchar(255)),RowNumber(Integer),Bestandsnaam (Varchar(255)), Pad (Varchar(255)), Grootte (Varchar(255)), Created (Varchar(255)), Modified (Varchar(255)), Accessed (Varchar(255)), Deleted (Varchar(255)), MD5 (Varchar(255)), SHA1 (Varchar(255))

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 !
Retreaving Data Based
I have tables called room_status and room_info

room_status= room_id : date : status

room_info= room_id : type : rate

What I want to do is only make an entry in room_status when
a room is booked, as it is obviously available otherwise(duh) but
I don't know how to format a SELECT statement to bring back
rooms available on a specific date by only returning results from
the room_information table which do not have an entry in the room_status
table for a specific date, which is the case if I don't formally record that
a room is available.

View Replies !
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 !
Query Based On Data Of 3 Tables
this is what I've been trying to implement:

I have, say, three tables.

One is a user table, with id, username, etc
Second is a question table with Question ID, Question, Category etc
And third is an "answers" table that keeps answers given by the users. It has the classic id key, and Question id and User Id columns.

What I want to do is this:
Select a random question of category 1 lets say from the questions table for which user X has no record of answering in the answers table.

View Replies !
How To Get Data Based On The Month And Year??
"select month(str_to_date(fmonth,'%M')) from company where id=2;"
(Query 1)
The fmonth in company has values like 'March,October etc,...'

this would give result as 4 for april (fmonth values in company table).

i have another table which has values based on the date.(Transaction table)

i want to fetch the values from the transaction table based on the date which is greater than the month of selected value fetched by the first query and of the year of current year....

i tried the query ,

"select *from transaction where date_format(transdate,'%Y %m') >=
date_format(curdate(),'%Y %m');"
This query returned the data which has a transdate >= 2006-10

i know that i have to combine the two query,but couldn't get those things.


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 !
Schedule Data Extractions Based On Requirements
I'd like to SCHEDULE a task to run automatically once per week that would EXTRACT all records from PHPBB_USERS which have either been newly created that week or were edited by the client within the same period.

The data would extract to a COMMA-DELIMITED file which would then be automatically emailed using the PHP mail command to an intended recipient so that she can MERGE the datafeed into a larger and more complex offline database.

Not entirely sure how this would be done, but I'm sure CRON would somehow get involved with the task.

View Replies !
Update Part Of Column Into Another Column
I'm looking for a way to update a SQL column with a portion of info from another column in the same table.

example of a sql command
--------------------------
UPDATE table1
SET table1.columnname1 = table1.columnname2
FROM table
WHERE blah blah blah

Here's the thing... I only need a portion of the data found in the source column. I'm not sure how I would do this then.

for example, the database has countries and states combined into one column like this 'US-DC', 'US-CA', US-FL', etc. I want to separate these into two columns, a country column and a state column.... and I dont want to go though all the results and do this line by line. How would I write the SQL command so that it puts just the country in the country column, and puts just the state in the state column, and it omits the dash all together.

any ideas?

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 !
Query For Month Data Based On Occurance Against Master List
I have a query running nicely. Now I'm trying to expand it.

It pulls the data from a table based on matching the id with another table and part of the grouping is by month and 2 other criteria. Now I'm trying to get the data pulled by month to pull only the info where the id matches the master file AND the FRANID's pulled are the same for each month. I'm trying to get a comparisson across times, but not every month has all FRANID's, depending on when they were entered and I ony want data that exists with matches over set months, starting for now with 12, perhaps also for 6 and 3 next time.

I've simplified what I'm doing above, but it is detailed below.....

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