 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
01-31-2008, 03:03 AM
|
#1 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Dozens of questions which I cannot find. v_v
Heres some questions which I cannot find online, cause it's all about crap PHP Tutorials with MySQL. Now
How would I insert two querys at once? in the same variable:
PHP Code:
$query = "SELECT * FROM `table`, INSERT INTO `table` (id,name,blah) VALUES(, 'blah', 'blah', 'blah');
How would I assign tables/columns/etc to a different column, say I wanted to inherit some columns like so:
PHP Code:
// I want t1's users to be t2's users $query = " SELECT t1.users,t2.users FROM t1,t2 SET `table1` AS `t1` AND `table2` AS `t2`";
How would I edit columns in the tables?
PHP Code:
$query = "TRUNCATE `table` WHERE `blah`='$blah'";
How would I move values from columns to other columns?
That's all the questions I have for now, I might ask some more later.. HALP!
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
01-31-2008, 03:06 AM
|
#2 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
If someone helps me out, they get a cookie! :D
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
01-31-2008, 03:11 AM
|
#3 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
We need a MySQL Guru. -_-
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
01-31-2008, 03:22 AM
|
#4 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
Surely you can wait 10min..... Its 24/7 staff you seem to want.
1. You cant execute more then one query though mysql_query, here some code I wrote that can enable you to do this in a different way Multiple mysql queries
2. I dont get what you are trying to do, why not select both via aliasing?
// I want t1's users to be t2's users
$query = " SELECT t1.users AS t1_users,t2.users AS t2_users FROM t1,t2;
3. Modify an existing MySQL column - Tech-Recipes.com
A quick google serach could have answered the second two
|
|
|
|
01-31-2008, 03:32 AM
|
#5 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
Quote:
Originally Posted by Orc
How would I assign tables/columns/etc to a different column, say I wanted to inherit some columns like so:
PHP Code:
// I want t1's users to be t2's users
$query = " SELECT t1.users,t2.users FROM t1,t2
SET `table1` AS `t1` AND `table2` AS `t2`";
|
From your code, it looks like you might be wanting to use something like the following:
SQL Code:
SELECT t1.users, t2.users FROM table1 AS t1, table2 AS t2 ;
Please be patient when asking questions; even though some of us are on the forums very often, we're not here to drop everything and respond immediately to new posts. Even if that were the case, it does indeed take a few minutes to draft a post. 
|
|
|
|
|
The Following User Says Thank You to Salathe For This Useful Post:
|
|
01-31-2008, 04:09 AM
|
#6 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by Salathe
From your code, it looks like you might be wanting to use something like the following:
SQL Code:
SELECT t1.users, t2.users FROM table1 AS t1, table2 AS t2 ;
Please be patient when asking questions; even though some of us are on the forums very often, we're not here to drop everything and respond immediately to new posts. Even if that were the case, it does indeed take a few minutes to draft a post. 
|
Okay, but thanks for answering one of my questions. :D
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
01-31-2008, 04:59 AM
|
#7 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
I think I figured out that Inner join can be used to combine data from other tables to make one table :D
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
01-31-2008, 07:50 PM
|
#8 (permalink)
|
|
The Acquainted
Join Date: Nov 2007
Posts: 166
Thanks: 0
|
Quote:
Originally Posted by Orc
I think I figured out that Inner join can be used to combine data from other tables to make one table :D
|
Yes, also LEFT JOIN and RIGHT JOIN. You can also do SELECT queries within other queries (as pointed out by buggabill). There's also UNIONs to do two queries at once.
Code:
SELECT name FROM cia WHERE population > (SELECT population FROM cia WHERE name='United States');
SELECT * FROM t1 UNION SELECT * FROM t2 UNION SELECT * FROM t3;
__________________
Eric
|
|
|
|
01-31-2008, 10:58 AM
|
#9 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
I'm wondering if I have to use queries for listing rows in a table, and updating, deleting, or inserting into tables. -_- I said I'm a newbie at MySQL. :/
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
01-31-2008, 01:10 PM
|
#10 (permalink)
|
|
The Contributor
Join Date: Jan 2008
Location: Maine, USA
Posts: 92
Thanks: 2
|
I believe...if I am wrong, someone correct me, please..to insert data from a SELECT query into another table do something like the following:
SQL Code:
INSERT INTO generals (name, rank, serialnum) SELECT name, rank, serialnum FROM allsoldiers WHERE rank="General"
The field names do not have to match, but the data type should.
By editing columns in a table, to what are you referring? Do you wish to change the data type or just the data in a specific column/field?
__________________
-- Bill
"Why is it drug addicts and computer aficionados are both called users?" -Clifford Stoll
|
|
|
|
01-31-2008, 01:12 PM
|
#11 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by buggabill
I believe...if I am wrong, someone correct me, please..to insert data from a SELECT query into another table do something like the following:
SQL Code:
INSERT INTO generals (name, rank, serialnum) SELECT name, rank, serialnum FROM allsoldiers WHERE rank="General"
The field names do not have to match, but the data type should.
By editing columns in a table, to what are you referring? Do you wish to change the data type or just the data in a specific column/field?
|
I was trying to list some news entries, then show a checkbox to delete it or edit it. :/
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
01-31-2008, 02:42 PM
|
#12 (permalink)
|
|
The Contributor
Join Date: Jan 2008
Location: Maine, USA
Posts: 92
Thanks: 2
|
Sorry for all the questions, but I have one more. Were you planning on adding or removing a column for each news story? Am I misunderstanding you? Are you actually trying to add or delete rows?
TRUNCATE will clean the table out and leave the structure intact. I don't think that is what you want to do...
To delete a row, here is a small example(assuming you had the id of the story):
SQL Code:
DELETE FROM newsstories WHERE id=idofstory
Changing data in a column requires you to do an UPDATE query.
example:
SQL Code:
UPDATE stories SET body=bodyofstory WHERE id=idofstory
__________________
-- Bill
"Why is it drug addicts and computer aficionados are both called users?" -Clifford Stoll
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|