Merging Two Querys
I have two query that I I would like to be one, but I can't figure out
how to do it. (mysql 3.23)
$sql = sprintf ("SELECT task,SUM(hours),login FROM activities WHERE
login='%s' group by login",$usuario);
$sql2 = sprintf ("SELECT SUM(hours) FROM activities WHERE login='%s'
AND month='%s' group by login",$usuario,$getdate);
View Complete Forum Thread with Replies
Related Forum Messages:
Two Querys In One
How can I make this both querys be only one recordset? select distinct grupo from sentient_campos where id_madre = 1 select distinct grupo_madre from sentien_campos where id_madre = 2
View Replies !
Multiple Querys
I'm working on a query where I'd like to be able to search one OR two attributes. I've come accorss a few postings that lead me to the code below. It works fine if I put something in both attributes but fails if I leave the second blanc. Can you help? SELECT * FROM books WHERE title LIKE '%$title%' AND title_sub LIKE '%$title_sub%' ORDER_BY print_id (p.s. I would lideally like to make the first attriubute optional. I may also want to add a few more attributes later)
View Replies !
Dates In Querys
I'm returning the month from a datatime stamp in a mysql query using the following: MONTH(theDate) AS tMonth Only problem is, if the month is before november, it doesnt not return the preceeding 0, so for example.. september I only get 9 not 09. Is there any way in the query to define this?
View Replies !
Multiple Querys Into One
How can I reduce multiple querys into 1 I have 1 main select PHP //get all the booking data from the tables, now I need to $cust_sql = mysql_query("SELECT DISTINCT customer.bid, customer.oid, customer.c_name, customer.pnumber, customer.mnumber, customer.party_names, customer.paid, booking.startdate, booking.enddate, booking.cid, booking.resort, booking.villa, booking.vtype, booking.adults, booking.children, booking.infno, booking.outfno, booking.atime, booking.cost FROM customer,booking WHERE customer.bid= '" . $_GET['id'] . "' AND booking.id='" . $_GET['id'] . "'"); if (!$cust_sql) { echo 'An error has occured with the db and is detailed below:<br> ' . mysql_error(); exit; } $row = mysql_fetch_row($cust_sql); I then run a another to return the country name using the booking.cid from the main result set. PHP $country_sql = mysql_query("SELECT DISTINCT country_name FROM country WHERE cid = '".$row[14]."'"); Is there a way to condense the 2 or more queries into the main one.
View Replies !
Mysql Shuts Down During Rapid Execution Of Querys
I am using version 4.0.12-nt of MySQL and when I hit the enter key rapidly I can't connect to the database. The result is a message is returned to me from mysql that says I can't connect because the database is down. If I only hit the 'enter' key once (to execute the page that my queries are on(their are four queries on this particular web page)) my queries execute just fine. We have noticed that this only happens when we:
View Replies !
20 Different Tables Querys Slowing Page Display
I have an issue with a very large PHP page that calls over 20 different MySql Statements. This page is loading somewhat slow and i want to speed things up. I have looked into sql caching applications like http://eaccelerator.net/ and http://www.danga.com/memcached/ which i may install later, but i feel they are more for pages that are called frequently, my page calls the same data less times but can call more than 2000 different versions of the data. Being that my page is a little over 1000 lines, putting it all here is not gonna happen. I will try to shorten the code using examples... After writing the blow code.. it may be really confusing. I have stuck the file on my server http://www.empiresolutions.net/clien.../green_bar.zip in case anybody whats to get a better look. This file in it current state works fine, just is slow. Any and all help is so appreciated. Another Question... Can anyone provide suggestions on how to bench-test my sql scripts to see exact improvment speeds? Each indent means the following query is nested. Query 1 (2 Join Tables) Query 2 (2 Join Tables) Query 3 (1 Table) Query 4 (4 Join Tables, While Loop) Query 5 (2 Join Tables) Query 6 (1 Table) Query 7 (4 Join Tables, While Loop) Query 8 (2 Join Tables) Query 9 (1 Table) Query 10 (1 Table, While Loop) Query 11 (2 Join Tables, Calls every 10 rows from Query 10) Query 12 (2 Join Tables, Calls every 10 rows from Query 10, same as Query 11 basically) Query 13 (2 Table, While Loop) Query 14 (1 Table) Query 15 (2 Join Tables, This query and subs are called 4 times in a FOR loop) Query 16 (2 Join Tables) Query 17 (2 Join Tables) Query 18 (1 Table) Query 19 (2 Join Tables) Query 20 (1 Table)
View Replies !
The Merging
i want to know about of the data bases merging , that i have 2 SQL databases from my forums i want to merg the old database with the new one .... without any lose of the users or Topices or ,,,,etc. is there any way to do so, ? is there any Script can do it quikly ?
View Replies !
Merging Databases
Suppose I have a relational database, called "BranchA." I have a second relational database, of identical structure to BranchA, but with different data, and this one is called BranchB. Can I merge the two, into, say, a BranchC somehow on occassion?
View Replies !
Sorting And Merging
I have a table in the following style : Artnr Detail ----- ------ 110391 grey and 100391 blue color 100392 Green 100393 black 100393 monitor .... So sometimes one article has more details. My problem is, i have to get rid of that and sort the table in this way : Artnr Detail ----- ------ 110391 grey and blue color 100392 Green 100393 black monitor Is there a way to manage this with mysql or does it need php scripting.
View Replies !
Merging INSERT
in my table I have an `id` column, which is set as the primary key as well as auto_increment. In my application I currently insert a new row into the database and then do a select query to find out what the `id` column of the newly inserted row is. Would it be possible to merge these to queries into one, so I could insert the row and then query the `id` column all in one statement
View Replies !
Merging Two Db Fields
I have two different databases, and I need to merge two fields into one fields. I have fld_user_name in db1 and fld_userlogin. Is there anyway that I can do this with out having to reenter each user.
View Replies !
Merging 2 Tables
Alright, i'm have this database where it has 7 tables. All of these tables have identical columns. However it contains information of different categories. The reason for that is to reduce the mess of having all in one tables. For one of my process, i need to combine all 7 tables together. Now, i have been searching high and low for a non-destructive method whereby i can stack all the tables' information into just one table. But what i see are things like JOIN that i can't use as i'm not joining tables through columns contain datas of the same domains. Code:
View Replies !
Merging Two Databases
I am working with 2 mysql databases for FamilyConnection CMS for my little family website. First database has 15 tables that's from an older version of fcms and the second database for a recent fcms version, has the 15 original plus 5 more new tables. How do I add the data in my old database into the new database?
View Replies !
Merging Two Tables
I have 2 tables. table: test1 +-----+-----------+------------+------------+ | id | client_id | contact_id | strings | +-----+-----------+------------+------------+ | 1 | 55 | 3 | A | | 2 | 66 | 9 | B | | 3 | 55 | 0 | C | | 4 | 77 | 0 | D | +-----+-----------+------------+------------+ table: test2 +-----+-----------+-----------+ | id | client_id | strings | +-----+-----------+-----------+ | 3 | 55 | one | | 20 | 55 | two | | 9 | 77 | three | | 11 | 33 | four | +-----+-----------+-----------+ test1.contact_id is test2.id index I need to get all one client rows from both tables. Is it possible? I have tried to use join with these tables, but it always leaves some rows out from result. Lets take for example needed results for client 55 +-----------+-----------------+---------------+ | client_id | test1.strings | test2.strings | +-----------+-----------------+---------------+ | 55 | A | one | | 55 | C | NULL | | 55 | NULL | two | +-----------+-----------------+---------------+
View Replies !
Merging Data
I have two databases with identical structure, and I am wanting to merge the data from one table in one database with the data from the same table in the second database. I have the following code, and it seems to run without any errors but the data is not merged. Can anyone help me? (SELECT name, uname, email, url, user_avatar, user_regdate, user_icq, user_from, user_sig, user_viewemail, actkey, user_aim, user_yim, user_msnm, pass, posts, attachsig, rank, level, theme, timezone_offset, last_login, umode, uorder, notify_method, notify_mode, user_occ, bio, user_intrest, user_mailok FROM first_database.xoops_users) (SELECT name, uname, email, url, user_avatar, user_regdate, user_icq, user_from, user_sig, user_viewemail, actkey, user_aim, user_yim, user_msnm, pass, posts, attachsig, rank, level, theme, timezone_offset, last_login, umode, uorder, notify_method, notify_mode, user_occ, bio, user_intrest, user_mailok FROM second_database.xoops_users)
View Replies !
Merging Rows?
Is it possible to merge rows in SQL? eg. I have rows that contain a product ID, sessionID, Colour, Size and quantity. Is it possible in SQL to merge the rows so that if a row contains the same product ID, session ID, colour and size then the rows would be merge adding the quantity fields? I'm using this to display the merged rows but is there a way to modify this to permanently merge the rows... the reason I want to do this is I want to be able to modify the quantities eg. the form shows 3 as the quantity but that might be made up of 2 rows of a 2 and a 1 so I would only want to update one of the rows with that productID not both. Code:
View Replies !
Merging Row Field To Another - Is It Possible
If possible I need to merge a row's field's data to an another row's field's data if possible. Here is an example of the rows : I need to, if possible when I do my .csv dump to append the order_item_id 3178's order_item_item_id to 3177's order_item_item_id . Is this possible using an advanced query?
View Replies !
Merging Like Fields
I have 2 tables that I would like to Join. Each table has a Date/Time stamp and logged mysqleratures from a specific room. I would like to Join these tables, but only have one Date/Time Table. This will be a full Join, sometimes one table will have a date/time, sometimes both will.
View Replies !
Merging Rows Within The Same Table
Got this trouble that worries me a lot: Say I have tables: "users" and "userDetails". table "users": Code: ID --- userName 1 xxx 2 yyy table "userDetails": Code: ID --- dept --- city --- date 1 1 NULL NULL 1 NULL 2 NULL 1 NULL NULL 3 Suppose the entries for the second table are entered at different time spans, or by different people. I want to join this tables together and (ON ID), so that it fills the null values in the second table somehow merging them or by some special technique which is hidden to me Running extra code (either PHP or MySQL) to sqeeze (alter) the second table and select afterwards is not acceptable. I'd like a single SELECT query which would do it, while keeping the original table entries. Desired selection result: Code: ID --- userName --- dept --- city --- date 1 xxx 1 2 3 It would also be nice to learn whether I can select among the non-null values in case they match according to some criteria (like ORDER BY)... In this case there would be another non-null field in the second table (e.g. entryID), and would sort in a descending order according to it.
View Replies !
Joining/Merging Two Tables Into One?
INSERT INTO test select testing.products_id,testing.products_percase,testing2.products_name, testing.products_weight, testing.products_model, testing.products_price, testing.products_quantity, testing2.products_description, where testing.products_id = testing2.products_id; This is what I have so far. Basically, I am trying to create one table with the values listed here from the two tables "testing" and "testing2". It says it is stopping near the where clause; does anyone know how to fix this issue so I can merge the two tables?
View Replies !
Question About Merging Big Tables?
In my applications, I need to merge three big tables(with different structures) into one big table, mySQL is: ============================= DROP TABLE IF EXISTS `my_final_table`; CREATE TABLE `my_final_table` ( ... UNIQUE KEY (`field1`,`field2`,`field3`,`source`), ); INSERT INTO `my_final_table` SELECT ***** FROM `table1`; REPLACE INTO `my_final_table` SELECT ***** FROM `table2`; REPLACE INTO `my_final_table` SELECT ***** FROM `table3`; ==============================
View Replies !
Tool For Merging Tables
I want to merge these tables into one big table and have the original tables replaced with views. Of course I can hand hack this, but I would rather have a tool do the work for me. Is there a tool that can do this and if yes where can I get it? The tool must take care of table data, foreign keys, datatypes and allow me to select columns that are the same.
View Replies !
Merging Data From A Many-to-many Relationship
I have three tables in my database: books {book_id*, title} authors {author_id*, name} book_author {book_id*, author_id*} The book_author table joins books and authors in a many-to-many realtionship. I join the tables with the following MySQL statement: SELECT book.title, author.name FROM book, book_author, author WHERE book.book_id = book_author.book_id AND book_author.author_id = author.author_id; The problem I have is that if a book has more than one author, the title appears multiple times for each instance of author as a seperate row in the table. eg. PHP & MySQL Web Development Luke Welling PHP & MySQL Web Development Laura Thompson Is there anyway to have the single title with multiple authors? When I GROUP BY book.title only one author is shown. eg. PHP & MySQL Web Development Luke Welling What I would prefer is something like this: PHP & MySQL Web Development Luke Welling, Laura Thompson
View Replies !
Merging Database Tables
I need advice on how to merge database tables. I have 3 tables that I want to compress into 1 table. All tables have the same columns, but different data within. Also, all tables have an auto-incremented primary key, so I need the id's to be changed, I guess - I'm not really sure about how that would be handled. If anyone can point me in the right direction here, please do.
View Replies !
Merging Two Fields In A Table!
I have used a join to bring two tables together, which works fine, but what I now have is 2 fields with dates in which I would like to order by, and at no point are these two dates overlapping, is there a way I can merge the two together, or order by both so as they overlap. My current SQL is: SELECT * FROM tblblog LEFT JOIN tblfilmreview ON tblblog.blog_date = tblfilmreview.date_watched UNION SELECT * FROM tblblog RIGHT JOIN tblfilmreview ON tblblog.blog_date = tblfilmreview.date_watched ORDER BY blog_date DESC, date_watched DESC Thankyou for any advice you may be able to give Dan Duke
View Replies !
Merging Multiple SELECT Queries
I have two tables, one storing the info of the users ( one user in each record ) and the other the ids of several users in a single record i.e. (4,2,9,6), (4,2,8,3) etc. For convenience sake, i'll call it table1 and table2. What is need is to retrieve the records from table two and from the user ids, get all the users first name from table1. My problem is that i want to keep it within one query. I have tried looking up union and joins but they don't seem to meet my needs. What i would like to achieve is maybe (user1_first_name, user1, user2_first_name, user2 etc.) Is this possible at all?
View Replies !
Merging The Results Of Multiple Tables
I have two tables. The first table is "users", the second table is "songs". The idea is that each user (one record in the users table) can upload several songs (several records in the songs table). I have it so that each new Song added, has a foreign key that points to a user record. So dozens of Songs could all point to the same user. My question is, I want to run a query that returns information about a user, including all their songs. So, the return table would look like: username alias songname1 songname2 songname3 username alias songname1 songname2 username alias songname1 songname2 songname3 songname4 etc.. The songnames come from the SONGS table, and username/alias come from the USERS table, but the final result should be one table. What I've managed to get working is returning all the songs of a user, but as different rows in the table: username alias songname Bob bob Happy Song Bob bob Sad Song Bob bob Super Song But I really want that to be returned as: username alias songname1 songname2 songname3 Bob bob Happy Song Sad Song Super Song So I want to merge n number of sub records, into a single user record, and return the results as 1 per user. How do I perform this feat?
View Replies !
Merging Two Tables With Diff Structures
I had installed on my phpBB3 Forum a mod to see what users viewed each topic, but then it started to not work properly with my other mods, so I found another one and installed it. But what happens is I want to put all entries that the first one had into the second one, but the thing is they have different table structures. One has one entry for every time the user viewed a topic, and the other has a view_count field, where it sums +1 every time the user visits the same topic again. The structures are: Old one: topic_id, user_id, date New one: topic_id, user_id, date, view_count Does anyone know how I could make a script in MySQL to go through the old table, and for each topic_id and user_id that are the same, make only ONE row and also count how many times forum_id and user_id are the same and throw them in the view_count field, and also for the date field, make it get always the date of the latest entry.
View Replies !
Forum Database Merging Question
I am very new to databases although I have backed up, and imported several forum db's using BigDump. That's as far as my knowledge goes i'm afraid. I have two similar smf forum dumps which I would like to merge into one database. If you imagine and old forum added to a new forum, or two different forums that decide to merge all their boards, posts and members into one. I have spent some time now reading up on sql, searching for scripts and creating databases in an attempt to get this to work. As I have said, I am a real novice at this kind of thing and would really appreciate some help. Basically a script would be a dream come true, but I have yet to find one. I am prepaired to read, learn and experiment if somebody could just point me in the right direction. Lastly, if this has been achieved before, a link to a guide or howto would be amazing.
View Replies !
Help Needed Merging 2 Different But Similar Tables
Can someone tell me how I can import tables from another non-Joomla mysql file into Joomla? Basically it is just from one mySQL database into another. I use phpMyAdmin to import and export the entire file but I don't know how to do queries. I tried exporting the source database and then renaming all the database names to match the ones I want to merge into but all that happened was a new table was created - no merging. I really just want to select the relevant 3 fields and match them up with the fields in the database table I want to import into. I have an old program that listed all the fields of database 1 in one column and database 2 in another and all I had to do was drag the fields across to make a match and the program did the rest. Perhaps there is a similar one out there? What I am trying to do is import all the articles I have built up using ccTiddlyWiki into Joomla. The only table names of relevance from the source file are: id - title- body IN other words, just the bare essentials. The target files has a table called jos_content with columns: id - title - title_alias - introtext - fulltext in that order and others but are not important. I think it is fairly simple but I am not trained enough. I have 200 items so it would save an enormous amount of time! It seems easy but I don't know enough about queries to do it well. I'm hoping that I can import the articles and then just go through the list in Joomla adding subtitles and so on to conform to Joomla database essentials.
View Replies !
Merging Unique Emails From 2 Tables
I have Table 1 and Table2 both having unique emails within them. Table 1 being the main email Container, I want INTERSECTION of Table 1 and Table2 and the UNIQUE emails between the two should be moved to Table 1. So now that Table 1 should have All the Unique Emails within itself and also between Table 1 and Table2 ex Table 1 A B C D Table 2 F G I B C So finally Table 1 should have A B C D F G I Note: values B and C already exist in Table 1 and should be ignored. How to write this query?
View Replies !
Merging Commands And Trying To Do A Selective Table Merge
Ok, the first problem is this. I have a large section of SQL commands to do, and I wish to know if there's a more efficient solution to do this. Background: I am working with multiple databases, each one is the same general format, but the data is dissimilar. It's incorrect in varying ways. The code below is intended to iron out some of those issues by pulling in fresh data from a second DB that is more accurate regarding aspect of the database as a whole. [MYSQL]DELETE FROM vendors WHERE entry=30239; INSERT INTO vendors SELECT * FROM ncdb_world.vendors WHERE entry=30239;[/MYSQL] The second issue is more complicated. I need a script that goes through the given table (in this case creature_proto) and selectively pulls in fresh data from another table when mindamage and maxdamage are both 1 or are both 0. The workaround I'm doing right now is manually looking at each entry in a table 36k entries long, and repeating the process every time there's a mass update. The code I'm using when I find a bad line is: [MYSQL]UPDATE creature_proto SET mindamage=11, maxdamage=14.19 WHERE entry=1721;[/MYSQL] Any assistance on these matters would be greatly appreciated. Thank you. - Aaron, Head Developer of MagicWoW Edit: Forgot to mention, I'm using MySQL 5.0.51b (comes standard with the version wampserver I'm using for MagicWoW)
View Replies !
Merging Data On Remote MySql Server
I've been tasked with installing the table structure from the master database onto a remote MySQL server. The remote server will accept data and periodically, merge/dump the data to the master server. I need help with the merge/dump issue. This doesn't sound like a replication (where two database servers are made to look identical) issue but 'merge' doesn't soud right either.
View Replies !
Tutorial On Back Up & Merging Tables And Database
I just want to make sure I don't end up throwing away some valuable data as I learn mySQL. 1. What is the best way to backup data? (copy the .frm files from the folder they are stored in? a backup function? other?) 2. How can I merge databases? (Basically I have two databases that are identical in format - same tables, same columns, but have different data in them) I'll be doing this on a regular basis - as during the week I'm collecting data in two locations and they syncing it up on the weekend. And the nature of it doesn't allow me to do everything at once. 3. Any suggestions on good books/resources to learn mySQL?
View Replies !
Merging Tables With Possibly Identical Data
Im looking to merge two tables in my db (or more specifically, insert one's values into the other). This post is pretty helpful for how to set up the merge, but my problem is my two tables will possibly contain identical data - and i dont want duplicate records Let me explain in more detail - table A contains spots which may be interesting for travellers in a given city. table B has the same data, but from a different source. Both will have the same columns (id, name, subtitle, cat_id, loc_id, address, added, by), but its the data IN the tables that might be identical. As i said before, i dont want duplicate records, so if the name of the listing is the same as one thats already already in the original table, how can i make it so it isnt inserted? If it helps, i already have a script which uses fuzzy string matching (written in php) using levenstein and metaphone methods. i dont know if its practical at all, but is there maybe a way we can use that to check each item in table B against the records already in table A before its inserted?
View Replies !
Error In Table Definition :: Merging Tables
I am looking towards merging multiple table sets (one per user) to a single set of tables with an extra field in each table for identifying the user a particular record belongs to. I'd prefer to make the abstraction layer on the database side to keep the changes in the application minimal. For that purpose, I am going to use triggers and create a set of views for each user. As I understand, all indexes should be prepended by user_id field, so instead of: create table username_posts ( id integer not null auto_increment , title varchar(32) , contents text , primary key (id) , key (title) ); I would have to use: create table global_posts ( id integer not null auto_increment , title varchar(32) , contents text , user_id integer not null , primary key (user_id, id) , foreign key (user_id) references users(id) , key (user_id, title) ); But I get "Error in table definition", as I am using InnoDB and it requires auto_increment column to be first in the list. I was thinking about using trigger instead of auto_increment but am not sure if that's the best way.
View Replies !
Dumpfile From Mysqldump Is Merging Rows For Multiple Inserts.
I am able to use mysqldump to view all the individual insertions of a table on an individual row. I have seen this occur before. Below is the desired format: INSERT INTO `database` VALUES (1,...,...); INSERT INTO `database` VALUES (2,...,...); INSERT INTO `database` VALUES (3,...,...); My dump producing the following instead: INSERT INTO `database` VALUES (1,...,...),(2,...,...),(3,...,...); Is there a way that I can configure the dump?
View Replies !
Logical OR On Columns? (Merging Two Or More Columns Into One Column)
Considering the following example table: Column1 | Column2 | Column3 =========================== NULL |"Value1" | NULL --------------------------- "Value2"| NULL | NULL --------------------------- NULL | NULL |"Value3" In each row only one column contains an actual value (a string in our example), the other columns are set to NULL. I would like to merge those columns into one single column, discarding the NULL entries. The desired result would look like this: Merged_Column ============= "Value1" ------------- "Value2" ------------- "Value3" A '"SELECT column1 OR column2 OR column3 as "Merged_Column"' doesn't work unfortunately. Is there an easy way to accomplish this on the SQL Server? The next problem I am going to face is that every column is in fact made of a different data type (ie. Date, Int). Is there a way to modify the merge select (if that's possible) to have it cast everything into a single specific type? Ie. make everything in the merged column a string.
View Replies !
|