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 One Table Value With Values From Another Table


I am trying to update one table value with values from another table, and I cannot get it to work. What am I doing wrong?

This is my SQL-command:
UPDATE tabel1 SET tabel1.name=tabel2.name WHERE tabel1.ID=tabel2.ID




View Complete Forum Thread with Replies

Related Forum Messages:
Update A Table With Values In Another
I have the following table

tableA
column_a
column_x
column_y
column_z

tableB
column_x
column_y
column_z

How do I update the rows of tableA that match rows of tableB (all rows
of tableB are unique)

What I want to acheive is a check against tableA.column_x with
tableB.column_x, if they match, then update the row in tableA.column_y
with the value of tableB.column_y and tableA.column_z with
tableB.column_z

View Replies !
Update Table Values
I have a csv.txt file with contacts and their information in it. Then I also have a table in mysql with the same contacts and their various information. I need to merge these to so that if a field value in the database is NULL the value that is in the csv.txt file is inserted into the database field.

I have been looking at the mySQL site on how to do this but have not been able to produce a working solution. Below is a more detailed example of what I am looking for. Code:

View Replies !
Update Values In Another Table
Table one has columns thread_forum_id and thread_thread (and a bunch of other stuff)

Table two has columns topic_id and post

I would like to populate thread_thread with the data from post however the columns thread_forum_id and topic_id need to correspond to each other when i do this.

for instance if topic_id = 1 and post = A
and another row is 2 and B then i want the resulting table one to have

1 and A
2 and B

but not
1 and B or the other way around.

View Replies !
Update Query Where Values Will Come From Other Table
I'm creating an update query which the value will come from another table.

I have here my current query which unfortunately makes the system hangs. Probably because of the query itself is not properly coded.

update boxes b inner join messages m
on b.ctnnumber = m.ctnno
set b.consigneerecv = m.CName,
b.consigneerecvdate = m.DateRcv,
b.phrecventered = "Y",
b.PhilStatus = "delivered",
b.prevreleasestatus = b.releasestatus,
b.releasestatus = "delivered",
b.PhilStatusDate = m.smsrecvdate,
b.phdelprice = "0.00",
b.phdelamt = "0.00",
b.recvrelation = m.Relation,
b.APRecventered = m.smsRecvDate
where b.consigneerecv = ''
or b.consigneerecv = 'NA'
or b.consigneerecv is null;

I'm thinking revising it so that it will not cause the system to hang but I don't know how. Guys please help me with this one. I also have this another idea which probably will not work. My idea was something like this:

Update table1 set table1.column1 = (select table2.column1 where table2.column1 = table1.column1),
table1.column2 = (select table2.column2 where table2.column1 = table1.column1), .....

View Replies !
How To Update A Table Using Values From Java ArrayList
I have a schema called Times with the following tables "machine_ID, numTime, timeDiff. In my java code, I have an ArrayList called machine_Time containing integer values which I want to insert into timeDiff. timeDiff has currently only '0' values. The part of my code is as follows:

PreparedStatement ps;

ps = con.prepareStatement("UPDATE Times SET timeDiff = ? WHERE machine_ID = 3000");
//the values to insert
for (int m = 0; m < machine_Time.size(); m++){
int mysql = ((Integer)(machine_Time.get(m))).intValue();
ps.setInt(1, mysql);
ps.executeUpdate();
}

View Replies !
To Update A Large Amount Of Values In 2 Columsn In 1 Table
I have a table that I need to change all values for all rows in 2 columns (used for mapping products).
Is there any SQL that will let me just say something like, update the 2 columns and insert these values in this order?

Example: these are the values: 2, 4, 6, 3, 4, 1, 3, 4
And those values would be inserted as the values for the first 8 rows

View Replies !
Inserting Into A Table Static Values And Values From An Existing Table
I am designing a content management system for my work-term and I basically need some help in data insertion. What I have is two tables, each with different field (Column) lengths. I am taking data I store in what is a mysqllate table ( basically mysqllate/default information), and appending it to another table which will be an actual production table that will be used in the website. This table still has 3 more fields so basically this is how it goes:

mysqllate table:

DOCID int(11) No
DTID int(11) No
ID int(11) No
requirements text latin1_swedish_ci No
reqd varchar(100) latin1_swedish_ci Yes NULL
date varchar(100) latin1_swedish_ci Yes NULL

Production Table:
RID int(11) No
DID int(11) No
DTID int(11) No
ID int(11) No
req mediumtext latin1_swedish_ci Yes NULL
reqd varchar(45) latin1_swedish_ci Yes NULL
date varchar(45) latin1_swedish_ci Yes NULL
comply varchar(45) latin1_swedish_ci Yes NULL
notes mediumtext latin1_swedish_ci Yes NULL

Therefore as you can see RID, comply and notes, are to be static values determined before the insertion of the data. I just do not want to have to query 900 rows of mysqllate info through PHP append the static values and then re-insert there has to be an easier way, perhaps through a view..

View Replies !
INSERT Into New Table, SELECT From Old Table, UPDATE Old Table With New Key
Code:

INSERT INTO retailers
(retailername, retailerdesc, retailerwebsite, retailerurl, active)
SELECT
datasource_retailername,
datasource_retailerdesc,
datasource_retailerwebsite,
datasource_retailertrackurl,
1
FROM
datasources_retailers_idx AS i
LEFT OUTER JOIN
retailers AS r
ON
r.retailername NOT REGEXP REPLACE(i.datasource_retailername, ' ','.+')

UPDATE datasources_retailers_idx SET idretailers=last_insert_id();

Here's what I'm trying to do:

* Select from old table
* check if there is a matching retailer in the new table
* If not, insert retailers details into new table
* Update a reference column in the old table with the INSERTID primary key value of that row from the new table

View Replies !
Finding Column Values Present In One Table, But Not In Another Table
have two tables, 'widgets' and 'widget_cats'. The primary key for widgets is 'widget.widget_id' and the key for widget_cats is a two-column key, 'widget_cats.widget_id,widget_cats.cat_id'. A particular widget_id can have more than one category, and so be present multiple times in the widget_cats table.

I'm looking to find the widget_id's of ids that are present in the widget_cats table, but ont in the widgets table. For instance say the pair '515,A98' is in the widget_cats table, but '515' is not present in the widgets table. I'd like '515' to be among the values returned.

View Replies !
Consolidating Values In One Table, Updating In Another Table
Table1
==========
Shoes Color
------ -------
Reebok Red
Nike White
Reebok Black
Reebok Blue
Nike Orange

How can I consolidate the values and copy them into a different existing table (Table2) so that Table2 looks like this? :

Table2
==========
Shoes Color
------ -------
Reebok Red, Black, Blue
Nike White, Orange

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 !
Inserting Values From 1 Table Into Another Table
I have 2 tables: A and B
Table A contains fields u, x and y
Table B contains fields u and z

Table A has all possible variations of u.
Table B has some of the varaiations of u in it.

My problem is that I'm trying to insert the z-values from Table B into Table A's y field and link them up based on the u-values.

I'm running into problems like truncating at row 0.

I've tried the following queries:

update TableA set y =(select TableB.z from TableB where TableA.u=TableB.u)

update TableA,TableB set TableA.y =(select TableB.z from TableB where TableA.u=TableB.u)

View Replies !
INSERTing Into A Table, With Values From Another Table
I'm programming a shopping cart application, where the products are categorized into different lines. I have a table that defines the different product lines, and now want to populate the product table.

However, the text file with the products in it, which I will use to populate the products table, uses the line NAME for each product, when I wish to use the line ID instead. To get the line ID, I would need to get the value from the line table.

My question is: is it possible to populate the products table with data from the products text file, as well as a column from the lines table?

That is, the INSERT (or LOAD DATA) statement will insert column values from the text file, but the line id from the lines table instead of the line name found in the file (WHERE line name = line name in the lines table).

I'm still not sure whether to use an INSERT, and write PHP code to go through the text file, or to use LOAD DATA for this task, because I don't know which statement would support what I'm looking for.



View Replies !
Update Table With Info In Other Table
i have a case like this:

table table1 (key, accumulator)

table table2 (key, counter)

i want to, for each table1.key = table2.key, update accumulator with the info in counter, something like this:

update table1 set accumulator=accumulator+table2.counter where (? counter is the value related with the same key as the one in table1)

how do you write a sentence like this one?

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 !
Table Design Question? House Table, Owner Table, Code Violations Table - Best Way?
Given the tables:

HOUSE
house_ID
address

OWNER
owner_ID
name
telephone...

HOUSE_OWNER_JOIN
?

CODE_VIOLATION_HISTORY
house_ID
violation_ID
violationStatement
...

My goal is to be able to track code violations of the house PER owner.

For example, I need to display a page that shows the current house with it's coe violations and a link to show the HOUSE's history of violation regardless of owner, Like:

House 1009283
Address
Past history (link to the following)

House History
2001-01-04 Owner: John Smith Code Violation: Gutter issue
1999-06-01 Owner: John Smith Code Violation: Faulty Steps
1998-03-02 Owner: Sam Spade Code Violation: Driveway carcks
1990-01-12 Owner: Keith Sledge Code Violation: Grass untidy


For the design of the HOUSE_OWNER_JOIN table, I thought of two ways I could go on this and this is where I need your help.

Option 1:
Have the HOUSE_OWNER_JOIN table keep dates so I can track the ownership changes that way:

HOUSE_OWNER_JOIN
houseID
ownerID
dateOwnershipBegan
dateOwnershipEnded

then I could look up all code violations by date and associate them with their rightful owner.

==================================================
Option 2:
Have the HOUSE_OWNER_JOIN table be the primary keeper of identity data by adding a new primary key and changing the CODE_VIOLATION_HISTORY table to reference that table by chaning the referencing key from house_ID to house_owner_ID:

HOUSE_OWNER_JOIN
house_owner_ID
houseID
ownerID
dateOwnershipBegan
dateOwnershipEnded

CODE_VIOLATION_HISTORY
house_owner_ID
violationStatement
...

View Replies !
Add Values To Table
I have a table tblMailingList. It has 3 columns; Name, EmailAdd, AutoID.

I am using
mysql> INSERT INTO pet
-> VALUES ('name1','u@me.com');

but I am unsure as to what to do for the AutoID field. If I use the example given, the error message says that the number of fields is different.
How do I get this info into my table?

View Replies !
Update Table From Another Table
I have 2 tables: country and ticket

country table contains countryId and countries

ticket table contains many fields, and a country field

the country table is new and consists of all countries to be used in a drop down on the ui, that is joined with the ticket table to display the correct country based on the id.

that being said.. the current ticket table also contains a country field which will be eliminated in the future. what I want to do is update the ticket table by finding the closest match to ticket.country in the countries.country table and then update the ticket.countryId to the countries.countryId.

This is what i have been doing country by country:
Expand|Select|Wrap|Line Numbers

View Replies !
How To Get UNIQUE Values From Table
I am trying to create a statement where it will return the UNIQUE values from a table, I think its the UNIQUE statment.

So a table may have 60 entries, 20 of them are X, 20 Y and 20 Z. I want it to return only X,Y,Z e.g. 3 returned entries.

View Replies !
Select Values From The 2 Different Table
Sample tables (company_id RK companies.id):

Companies

id company

1 …

2 …

3 …

Locations

id company_id location revision

1 1 … 1

2 2 … 1

3 1 … 2

4 1 … 3

5 2 … 2

6 1 … 4


How to write an SQL query to select values from the following columns (companies.company, locations.location) where locations.revision value will be the highest for each company

I try

Select distinct companies.company, locations.location from Companies, Locations where companies.id=Locations.company_id order by locations.revision

View Replies !
Duplicate Values For Another Value In The Same Table
I have a permission table that gives a userID permission to a module and the any actions within that module.

What I want to do is duplicate his permissions to another user.

Permission table has:

id (PK)

userID (FK)

module

action

When I do an insert and do a select of the values of the first user, it says It cannot use the target table in the FROM clause.

View Replies !
DISTINCT Table Values
I use DISTINCT to select distinct values of one column... but i can not use distinct selecting more values of that row.

select DISTINCT(field1) from table works
select DISTINCT(field1), field2, field3 from table does not work



View Replies !
Editing Values In A Table
I just moved from SQL Server to MySQL and in the Enterprise Manager in SQL Server I could query the entire table and then modify the values with the table without writing an UPDATE statement.
I cannot do that in one of my tables because the EDIT at the bottom is greyed out. There are other tables where I can make a modification to any value I want within the table.

View Replies !
INSERT Values From One Table To Another
In table A i have a.id and name and in table B, i have b.id, a.id(FK) and owns.

Table A
--------------
a.id | name |
--------------
12 | James |
13 | Paul |
14 | Tom |
15 | Andy |


Table B
--------------

b.id | a.id | owns |
--------------------
1 | 12 | Car |
2 | 12 | Bike |
3 | 13 | PC |

Now what i want is to add two new names to table A which will be Tom and Andy and have the same data in table B for Tom and Andy with just different b.id (PK).

How can i insert this new data in table B using insert?

View Replies !
Edit Values In Table Through GUI
I wonder which GUI tool I can use if I want to edit some values in a table? I can't find it in Query Browser. Do I really need to execute SQL to make a simple change to a field?

View Replies !
Returning Values That Are In One Table, But Not In Another
I'm looking for a query to return values which occur in one table, but not in the other.

Say we have two tables (table_1, table_2) each with a column titled "appointments".

I want a list of results for appointments which are in table_1, but not in table_2

I have tried the following, but all I get is a huge list of duplicate appointments which occur in both tables:

SELECT table_1.appointments
FROM table_1, table_2
WHERE table_1.appointments<>table_2.appointments;

I've also tried 'NOT IN' for this but the result was just the same.

View Replies !
Get The 3 Highest Values From A Table
My problem is to get the 3 highest values from a table

View Replies !
Most Common Values In Table
I've been looking around the MySQL and PHP documentation to no avail,

Basically, say we have a table of names:

id, name
1, Danny
2, Sam
3, Kerry
4, Danny
5, Paul
6, Sam
7, Kerry
8, Danny
9, Jack
10, Hudson

...and we want to determine the most popular, second most popular, etc. In this example, the most popular name is Danny (3 rows), the second most is tied between Sam and Kerry (2 rows each), then Jack, Hudson and Paul only have 1 row each.

In the case of a tie, I would simply sort the two rows alphabetically. The resulting popularity ranking would be:

1) Danny (3 results)
2) Kerry (2 results)
3) Sam (2 results)
4) Hudson (1 result)
5) Jack (1 result)
6) Paul (1 result)

Is there any way I can do this with MySQL?

View Replies !
Generating A Table With Missing Values In SQL
I have the following table:

+------+------+------+-----------+
|ID |GROUP |CODE |ANSWER |
+------+------+------+-----------+
|1 |1 |001 |01-01-2003 |
|2 |1 |002 |Yes |
|3 |1 |003 |NA |
|4 |1 |004 |297797 |
|5 |1 |005 |0 |
|6 |2 |002 |Yes |
|7 |2 |004 |297852 |
|8 |2 |005 |1 |
+------+------+------+-----------+

This means that code 001 and 003 of group 2 are missing. Result of the
query should be:

+-------+-----------+-----------+-----------+-----------+--------+
|GROUP |ANSWER1 |ANSWER2 |ANSWER3 |ANSWER4 |ANSWER5 |
+-------+-----------+-----------+-----------+-----------+--------+
|1 |01-01-2003 |Yes |NA |297797 |0 |
|2 |NULL |Yes |NULL |297852 |1 |
+-------+-----------+-----------+-----------+-----------+--------+

The missing values should be replaced by a NULL value in my resultset.
Is this possible? I don't have any clue how my query should look like,
can anyone help me and show me a solution?

View Replies !
Renaming Values In Table With ENUM
It seems that this table was created with some ENUM data types so I'm trying to figure out how this works. I can post the script that created this table but basically I'm trying to rename a value in this column document_type ENUM('FAQ', 'Sheet', 'Marketing Resource', 'Teacher Guide', 'Reference / User Guide') NOT NULL,

I'm not sure how this array is stored and what would happen if I tried to rename the value ....

View Replies !
Renumber Mysql Table Values
There are 100000 rows in a table, I need to renumber them from
1,3,6,8,11,14,21,55,888,1000,9999...99999
to
1,2,3,4,5,6,7,8,9,10,11,12,13,14...
etc
I also need to update an associated table, so its going to need to lock the tables, find the lowest available index in table1, then update table1 index, and then update table2 to use the same index as well, then unlock tables

What would be the procedure to do that?

View Replies !
An Enum Field Using Values From Another Table
The first table, called genus, contains several fields, the important one in genus is name, and there are others about the individual plant types.

The second table 'plants' needs one field for the genus name, so that I can link tables on this. If there a way to make a foreign key from the genus table into an enum field on the second? My idea is that then, with phpmyadmin or similar I can just select the genus name from a list when entering new plant data.

View Replies !
Updating A Table To Increment Values
Question, if I want to update all values in a certain column to increment by one, what statement could I use? In quasi-MySQL, this is my pseudocode:

UPDATE table SET fields=[previous_val+1] where [previous_val]>[my_val]

Or do I HAVE to run a SELECT query, increment the value, and THEN Update it?

I was just thinking there'd be an easier way.

View Replies !
How To Autoupdate One Field From Another, Using Table Values?
I am trying to update a box with data from a table through typing an input-code in another box. More to the point, I am trying to be able to get "state" data into a box next to the zip-code box, using the zip-code as input. It is supposed to not need the input of state, but update it from a two-column table where column 1 contains zip-code, and column 2 contains the respective states. Mind you, these are not really "states", but more like counties, Norwegian counties...

Is there a way to do this, preferably using php? The table is located in my mysql database.

Really hope for a good answer to this issue, as I am beginning to lose my hair over this - quite possibly rather simple - question..


View Replies !
Prevent Values That Do Not Exist In Another Table
products
manufacturer
category

Example:

CREATE TABLE categories (category_ID int(6) AUTO_INCREMENT NOT NULL PRIMARY KEY, category_Name varchar(25));

CREATE TABLE products (product_ID int(6) AUTO_INCREMENT NOT NULL PRIMARY KEY, product_Name varchar(30), quantity varchar(10), price float(5,2), category int(6), manufacturer int(6));

CREATE TABLE manufacturer (manufacturer_ID int(6) AUTO_INCREMENT NOT NULL PRIMARY KEY, manufacturer_Name varchar(30));

mysql> select * from products; select * from categories; select * from manufacturer; .....

View Replies !
Getting The Highest Values Of A Category In A Table
Here's my table

mysql> select * from messages;
+------+------+---------------------+-------------+
| cid | mid | sent | text |
+------+------+---------------------+-------------+
| 100 | 1 | 0000-00-00 00:00:00 | 321 |
| 100 | 2 | 2007-09-21 00:00:00 | 07921 |
| 100 | 4 | 2007-10-21 00:00:00 | 07=10=21 |
| 103 | 9 | 2007-09-22 00:00:00 | 07922 |
| 103 | 10 | 2007-11-22 00:00:00 | last of 103 |
+------+------+---------------------+-------------+
5 rows in set (0.00 sec)

What I want is a query to extract one row for each 'cid' value - and that row to be the one with the most recent date.
i.e. what I want is
mysql > **mystic inctantation goes here**

+------+---------------------+-------------+
| cid | max(sent) | text |
+------+---------------------+-------------+
| 100 | 2007-10-21 00:00:00 | 07=10=21 |
| 103 | 2007-11-22 00:00:00 | last of 103 |
+------+---------------------+-------------+
2 rows in set (0.00 sec)

I can get the first two rows OK, but I can't pull out the correct text line: FWIW here's my lame atmysqlt...

mysql> select cid, max(sent), text from messages group by cid;
+------+---------------------+-------+
| cid | max(sent) | text |
+------+---------------------+-------+
| 100 | 2007-10-21 00:00:00 | 321 | <-- see we have the wrong 'text' rows here
| 103 | 2007-11-22 00:00:00 | 07922 | <-- see we have the wrong 'text' rows here
+------+---------------------+-------+
2 rows in set (0.00 sec)

View Replies !
Insert Values Only If They Do Not Already Exist In Table
I want to insert some values from one table (A) into another table (b). However there are some values in table A which exist two times in table A. I only want to insert values one time. So If a certain field value also exist in some other row (same fieldname) then I don't want to insert it twice. It doesn't matter which of the two rows will be inserted.

Can this be done with MySQL? Maybe with some Control Flow Functions?

View Replies !
Accepting Values As NULL When Not In Another Table
Is it possible to perform a SELECT query on multiple tables and simply accept one of the values as NULL if not in another table rather than the whole query failing?

For instance, if "rec_id" exists in "table_1" for certain but it is uncertain if it exists in "table_2", is it possible to return the query with a variable assignment stating whether "rec_id" was or wasn't found in "table_2"?

I am hoping I can do this without a LEFT OUTER JOIN as the query is fairly complex and involves five different tables. Whenever results are fetched I simply need to know if rec_id is or isn't in table_2 if it is found in table_1.

As there are frequently over 10,000 result rows returned it wouldn't be sound to put this into a seperate loop that queries with each rec_id to see if it is in table_2.

I have tried "SELECT table_1.rec_id, table_2.rec_id FROM table_1, table_2 WHERE table_2.rec_id=table_1.rec_id OR table_2.rec_id IS NULL" but this returns no records.

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 !
How To Select Entries That Don't Have Certain Values From Another Table.
I writing this little traffic trading script and I have the following tables.

Table alt_outlinks with fields:

linkid - bigint primary auto-increment
gameid - bigint
partnerid - bigint
url -varchar(255)

Table ipchecktable with fields:

ipid - bigint primary auto-increment
partnerid2 -bigint
visitor IP (255)

So when a visitor comes, I track his referring IP.

What I want to do is to select the first entry from alt_outlinks where the referring IP is not present in ipchecktable for a certain partnerid in alt_outlinks.

partnerid2 tracks traffic trade partners I've already sent a hit from this IP today.

Basically for a certain game, there are several links a gamelink can go to. All gamelinks for the same game have the same gameid but different partnerids and URLs.

I just want to select a partner that I have not sent traffic to yet today.

View Replies !
INSERT INTO Table (vars) VALUES(vals)
I am trying to use the following command:
INSERT INTO sr_main (originator,symreq) VALUES (A.Person,269);

Whenever I enter the command above I get the following error:
ERROR 1054 (42S22): Unknown column 'A.Person' in 'field list'

I am confused because the error refers to my _value_ 'A.Person' as a column!? Do string values need to be surrounded with quote marks of some type? I have already tried the obvious (to me) quote markers, e.g. ", '

The data is accepted if I use this command:
INSERT INTO sr_main (originator) VALUES (269);

I actually have a lot more fields and values than shown, and ideally would like to use the command type:

INSERT INTO tablename (field1,field2,field3) VALUES (1,2,3)

Code:

View Replies !
Query To Insert 2 Foreign Key Values In Table
I want to insert 2 foreign key values along with some other value into table ....

View Replies !
How Do I Insert Values In A Pre Created Table Using Procedures ?
I have a problem in creating a procedure for inserting values into a precreated table say Emp(Empno,Deptno,Skill)

the values have to be inserted through the procedure ...

View Replies !
Select From Table (multiple Values From Same Field)
Is it possible to do a "select * from table where id=value1 and id=value2"? I have tried this and the query returns no data despite the fact that the table has records that match the criteria in the select?

View Replies !
Counting Occurrences Of Values In Table Column.
I have two tables;

Table 1;

Agent_ID UserID First_Name Last_Name

1ShadShad Mortazavi
2Harry Harry Potter
Table 2;

Recording_IDAgent_ID Status GSM_File etc
11 000001.gsm
21 0 00002.gsm
32 100003.gsm
41 200004.gsm
51 100005.gsm
61 200006.gsm
72 100007.gsm

Status 0 = Red, 1 = Yellow and 2 = Green

I would like a query that returns the number of occurrences of Red, Yellow, Green against each agent

so the data returned would look something like this;

NameREDYellow Green
Shad Mortazavi 2 0 2
Harry Potter 0 2 0

I'm using MySQL version 3.23.58

I can do this programmatically in Perl with several query's; but this is CPU intensive. If I could get this in one query I it would save time.

View Replies !
Selecting Unique Values From A Table (NOT DISTINCT!)
Lets say we have a table that has the field photo_id and has values of it many times. For example 245 can exist any number of times (1, 5, 8, e.t.c.).

I want to select the values that exist in the table ONLY ONCE. Please note that i dont want to select each value once (using DISTINCT), that would return all the values that exist in the table.

For example lets say the table has the following values:

245
563
776
224
563
563
776
776
776
776

The query i want to make should return only the values 245 and 224 as 563 and 776 exist many times in that table.

View Replies !
Replace Some Username Values With The Users ID In A Different Table
I really can't figure this out. I want to replace some username values with the users ID in a different table.

The tables are

pictures
user (Example FRED)
picture (Example pic.gif)

users
id (Example 5233)
user (Example FRED)

What I want to do is replace the user column in pictures with the correct id from the users table

So in the pictures table, it would no longer be FRED it would be 5233

Is there a query I can run to do this?

I'd really appreciate some feedback

View Replies !

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