Can I have a table with few rows in which the second row to start under the second column?
Something like this:
+-----------+----------------+
| | |
| | |
+-----------+----------------+
| |
| |
+-----------+----------------+
| | |
| | |
+-----------+----------------+
No, you cannot. But you can make it look like so by using right border and background colors.
Working example: http://jsfiddle.net/gkuQD/
You could have:
<tr><td>Content1</td><td>Content2</td>
<td> </td><td>Content3</td>
<td>Content4</td><td>Content5</td></tr>
This may be what you're looking for.
Related
Long story short, I need to be able to combine two tables (one is a continuation of the previous with a little overlap). I then need to set one column to be a Primary Key, which means no duplicates. When I tried to just use the Import Wizard in SQL Management Studio and import one table into the other, it just added all the data from one table into the next. I need to figure out some way or SQL command that will import all the data from the new table into the older table, and replace any existing duplicate data with the ones from the newer table.
Think of it like this, I have two tables with the following data:
People_Old table
+------+--------+
| Name | Color |
+------+--------+
| Mary | Blue |
| Katy | Yellow |
| Jim | Green |
| John | Red |
+------+--------+
People table
+------+--------+
| Name | Color |
+------+--------+
| Jim | Silver |
| John | Brown |
| Greg | Purple |
| Liz | Pink |
+------+--------+
Assuming the "Name" column are suppose to be a Primary Key, I would like to add the data from the newer "People" table into the older "People_Old" table, but replace the overlapping data so there are no duplicates. In this example, I would like the final "People_Old" table to be:
+------+--------+
| Name | Color |
+------+--------+
| Mary | Blue |
| Katy | Yellow |
| Jim | Silver |
| John | Brown |
| Greg | Purple |
| Liz | Pink |
+------+--------+
Use the REPLACE statement, something like:
replace into people_old select * from people;
DROP TABLE IF EXISTS old;
CREATE TABLE old
(Name VARCHAR(12) NOT NULL PRIMARY KEY
,Color VARCHAR(12) NOT NULL
);
INSERT INTO old VALUES
('Mary','Blue'),
('Katy','Yellow'),
('Jim','Green'),
('John','Red');
DROP TABLE IF EXISTS new;
CREATE TABLE new
(Name VARCHAR(12) NOT NULL PRIMARY KEY
,Color VARCHAR(12) NOT NULL
);
INSERT INTO new VALUES
('Jim' ,'Silver'),
('John','Brown'),
('Greg','Purple'),
('Liz' ,'Pink');
SELECT * FROM old;
+------+--------+
| Name | Color |
+------+--------+
| Mary | Blue |
| Katy | Yellow |
| Jim | Green |
| John | Red |
+------+--------+
SELECT * FROM new;
+------+--------+
| Name | Color |
+------+--------+
| Jim | Silver |
| John | Brown |
| Greg | Purple |
| Liz | Pink |
+------+--------+
INSERT INTO old
SELECT name
, color
FROM new
ON DUPLICATE KEY UPDATE old.color = new.color;
SELECT * FROM old;
+------+--------+
| Name | Color |
+------+--------+
| Mary | Blue |
| Katy | Yellow |
| Jim | Silver |
| John | Brown |
| Greg | Purple |
| Liz | Pink |
+------+--------+
6 rows in set (0.00 sec)
I have a table album that contains about 1000 rows. I want to update all rows.
Table album have a column named path. See full table structure below.
+---------------------------------------------------------------------------------------------+
| id | name | path |
+---------------------------------------------------------------------------------------------+
| 1 | Believe | Believe |
+---------+-----------+-----------------------------------------------------------------------+
| 2 | A Promise | A Promise |
+---------+----------+------------------------------------------------------------------------+
| 3 | Forever | Forever |
+---------------------------------------------------------------------------------------------+
I want to update path here. Want to add album in path for SEO friendly URLs. table should look like this for that goal.
+--------------------------------------------------------------------------------------------------+
| id | name | path |
+--------------------------------------------------------------------------------------------------+
| 1 | Believe | Believe |
+---------+-----------+----------------------------------------------------------------------------+
| 2 | A Promise | A Promise|
+---------+----------+-----------------------------------------------------------------------------+
| 3 | Forever | Forever |
+--------------------------------------------------------------------------------------------------+
I can't figure out how to use LIKE here, what to insert between % %. Please help me. Thanks in advance.
Is it possible to have a table where one of the columns is divided at a different position than the rest of the columns?
An example:
+---+---+---+
| | | |
| +---+---+
| | | |
+---+ | |
| | | |
+---+---+---+
You can do this via the rowspan property.
A table cell with rowspan will occupy the current row and that many rows below it. You must remember to omit the corresponding table cells on subsequent rows.
http://jsfiddle.net/BmJaw/
I have a question which relates to MySQL. The problem can be seen in these two images:
http://imgur.com/NrOwSxS,yPo9Cra
http://imgur.com/NrOwSxS,yPo9Cra#1
Does anyone know why MySQL is doing this? It should show up as a nice and neat table, not this bundle of gibberish. Thanks in advance! :D
First, to show that there's nothing really wrong, try this query:
SELECT firstname FROM contact_info
That should look good. Now try this:
SELECT firstname, lastname FROM contact_info
That's how you pick individual columns.
Really you want to capture output to a file, this page shows you how: The MySQL Command-Line Tool
Then you can learn to use other programs to format it nicely.
I assume you created your table somewhat like this:
create table automobile (make char(10),model char(10),year int, color char(10), style char(50), MSRP int);
insert into automobile values ('Ford','Mustang',2006,'Blue','Convertible',27000);
insert into automobile values ('Toyota','Prius',2005,'Silver','Hybrid',22000);
insert into automobile values ('Toyota','Camry',2006,'Blue','Sedan',26000);
insert into automobile values ('Dodge','1500',2005,'Green','Pickup',26000);
so a
describe automobile
will show you your columns as:
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| make | char(10) | YES | | NULL | |
| model | char(10) | YES | | NULL | |
| year | int(11) | YES | | NULL | |
| color | char(10) | YES | | NULL | |
| style | char(50) | YES | | NULL | |
| MSRP | int(11) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
as long as your columns in total are smaller than your terminal's width you should see
the expected result:
mysql> select * from automobile;
+--------+---------+------+--------+-------------+-------+
| make | model | year | color | style | MSRP |
+--------+---------+------+--------+-------------+-------+
| Ford | Mustang | 2006 | Blue | Convertible | 27000 |
| Toyota | Prius | 2005 | Silver | Hybrid | 22000 |
| Toyota | Camry | 2006 | Blue | Sedan | 26000 |
| Dodge | 1500 | 2005 | Green | Pickup | 28000 |
+--------+---------+------+--------+-------------+-------+
if you'd like the result smaller then pick the columns you'd like to see e.g.
select make,model from automobile
mysql> select make,model from automobile;
+--------+---------+
| make | model |
+--------+---------+
| Ford | Mustang |
| Toyota | Prius |
| Toyota | Camry |
| Dodge | 1500 |
+--------+---------+
to make the content of a column smaller you may use the left string function
select left(make,4) as make, left(model,5) as model,left(style,5) as style from automobile;
+------+-------+-------+
| make | model | style |
+------+-------+-------+
| Ford | Musta | Conve |
| Toyo | Prius | Hybri |
| Toyo | Camry | Sedan |
| Dodg | 1500 | Picku |
+------+-------+-------+
You can try supplying a line separator character in the end.
mysql> LOAD DATA LOCAL INFILE *file_path* INTO *table_name* LINES TERMINATED BY '\r\n';
Separator character may vary for editors. In Windows, most editors use '\r\n'.
In mysql i need to get enum fields side by side in a column when i run a query with group by , just like as follows.
There is table as like below
mysql> describe tabex;
+---------+----------------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+----------------------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| personid| int(11) | YES | | NULL | |
| color | enum('red','blue','white') | YES | | NULL | |
+---------+----------------------------+------+-----+---------+----------------+
there are different shirts , the column personid describes the that person id and color indicates the color of his shirt..
the data in table is as follows
mysql> select * from tabex;
+----+----------+-------+
| id | personid | color |
+----+----------+-------+
| 1 | 1 | red |
| 2 | 1 | white |
| 3 | 2 | blue |
| 4 | 2 | red |
+----+----------+-------+
4 rows in set (0.00 sec)
when i ran a query i am getting results like this
mysql> select personid , color from tabex group by personid;
+----------+-------+
| personid | color |
+----------+-------+
| 1 | red |
| 2 | blue |
+----------+-------+
but i want the result like below
+----------+-------------+
|personid | color |
+----------+-------------+
|1 | red,white |
|2 | blue,red |
| | |
+----------+-------------+
how can i get the result as above by using group by and aggregation (if any for enum).
that is here i want to get the result for enum fields as like we will get by using count or sum functions and group by .
The GROUP_CONCAT() aggregate function does what you want:
SELECT personid, GROUP_CONCAT(color) colors
FROM tabex
GROUP BY personid
This works with any kind of field, not just ENUM.