Shantanu's Blog

Corporate Consultant

April 30, 2005

 

MySQL Case Study - 17

Different type of auto_increment

I have question about how I can get top 2 rows for each group. like I
have table test
| seqno |
+-----------+
| 000000122 |
| 000000123 |
| 000000123 |
| 000000123 |
| 000000336 |
| 000000346 |
| 000000349 |
| 000000427 |
| 000000427 |
| 000000427 |
+-----------+------+

I like have
+-----------+------+
| seqno | item |
+-----------+------+
| 000000122 | 1 |
| 000000123 | 1 |
| 000000123 | 2 |
| 000000123 | 3 |
| 000000336 | 1 |
| 000000346 | 1 |
| 000000349 | 1 |
| 000000427 | 1 |
| 000000427 | 2 |
| 000000427 | 3 |
+-----------+------+

Then I can have select * from test where item <3 engine="myisam;"> select * from seqs;
+-----------+----+
| seqno | id |
+-----------+----+
| 000000122 | 1 |
| 000000123 | 1 |
| 000000123 | 2 |
| 000000123 | 3 |
| 000000336 | 1 |
| 000000346 | 1 |
| 000000349 | 1 |
| 000000427 | 1 |
| 000000427 | 2 |
| 000000427 | 3 |
+-----------+----+
10 rows in set (0.00 sec)


mysql> select * from seqs where id < 3;
+-----------+----+
| seqno | id |
+-----------+----+
| 000000122 | 1 |
| 000000123 | 1 |
| 000000123 | 2 |
| 000000336 | 1 |
| 000000346 | 1 |
| 000000349 | 1 |
| 000000427 | 1 |
| 000000427 | 2 |
+-----------+----+
8 rows in set (0.00 sec)

If you already have a primary key you can drop and recreate it.
ALTER TABLE source_table DROP PRIMARY KEY, ADD COLUMN seqcounter int
auto_increment, ADD PRIMARY KEY (seqno, seqcounter);

~~~
You can also use variables to populate the interger column without using the primary key.
alter table seqs add column myid int;
set @a:=0;
set @b:=0;
update seqs set myid=if(seqno=@b, @a:=@a+1, if(@b:=seqno, @a:=1, 0));
(This method will not work if the seqno is not ordered)

 

MySQL Case Study - 16

Order by version numbers?

In my table I have one varchar(20) column where I store version number.
Version looks like:
1.1.2
1.2.1
1.10.3
It is possible order this column in natural order (1.2 before 1.10)?

_____

CREATE TABLE ss (version VARCHAR(13));
INSERT INTO ss VALUES ('1'),('1.1'),('1.2.1.2'),('1.10.1'),('1.2'), ('1.4.1'),('2.1'),('2.2.1.2'),('2.10.1'),('2.4.1');

If each part is no larger than 255, you can leverage INET_ATON() to do what you want (up to the 4th part). The trick is making each of these look like an IP first by using CONCAT to add '0.0.0' to make sure every row has at least 4 parts, then SUBSTRING_INDEX to pull out just the
first 4 parts.

SELECT version FROM ss
ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(version,'.0.0.0'),'.',4));

+---------+
| version |
+---------+
| 1 |
| 1.1 |
| 1.2 |
| 1.2.1.2 |
| 1.4.1 |
| 1.10.1 |
| 2.1 |
| 2.2.1.2 |
| 2.4.1 |
| 2.10.1 |
+---------+
10 rows in set (0.00 sec)

Now, I must point out that because we are sorting on a function of the column, rather than on the column itself, we cannot use an index on the column to help with the sort. In other words, the sorting will be relatively slow.

One solution would be to separate the parts into separate columns, each of which could then be an appropriately sized integer (TINYINT, perhaps). You could use 0 or NULL for the missing parts, as you see fit (NULLS preserve the output format you specified, e.g. 1.1, but complicate matching).

CREATE TABLE ss2 (v1 TINYINT UNSIGNED, v2 TINYINT UNSIGNED,
v3 TINYINT UNSIGNED, v4 TINYINT UNSIGNED,
KEY version_idx (v1,v2,v3,v4));

INSERT INTO ss2 VALUES (1,NULL,NULL,NULL), (1,1,NULL,NULL), (1,2,1,2), (1,10,1,0), (1,2,0,0), (1,4,1,0), (2,1,0,0), (2,2,1,2), (2,10,1,NULL), (2,4,1,NULL);

Glue the parts together with CONCAT_WS() when you select them, and sort
by all 4 parts:

SELECT CONCAT_WS('.',v1,v2,v3,v4) version FROM ss2 ORDER BY v1,v2,v3,v4;
+----------+
| version |
+----------+
| 1 |
| 1.1 |
| 1.2.0.0 |
| 1.2.1.2 |
| 1.4.1.0 |
| 1.10.1.0 |
| 2.1.0.0 |
| 2.2.1.2 |
| 2.4.1 |
| 2.10.1 |
+----------+
10 rows in set (0.00 sec)

In this case, the multicolumn index on the 4 parts will be used to sort.

Another option would be to use INET_ATON() when storing the values.

CREATE TABLE ss3 (v INT UNSIGNED, KEY version_idx (v));

In this case, you'd have to use 0 for missing parts.

INSERT INTO ss3 VALUES (INET_ATON('1.0.0.0')), (INET_ATON('1.1.0.0')),
(INET_ATON('1.2.1.2')), (INET_ATON('1.10.1.0')),
(INET_ATON('1.2.0.0')), (INET_ATON('1.4.1.0')),
(INET_ATON('2.1.0.0')), (INET_ATON('2.2.1.2')),
(INET_ATON('2.10.1.0')),(INET_ATON('2.4.1.0'));

Use INET_NTOA() when selecting to display dotted numbers, but sort by
the values already in the column.

SELECT INET_NTOA(v) version FROM ss3 ORDER BY v;

+----------+
| version |
+----------+
| 1.0.0.0 |
| 1.1.0.0 |
| 1.2.0.0 |
| 1.2.1.2 |
| 1.4.1.0 |
| 1.10.1.0 |
| 2.1.0.0 |
| 2.2.1.2 |
| 2.4.1.0 |
| 2.10.1.0 |
+----------+
10 rows in set (0.00 sec)

As with the second version, the index on v will be used for the sort.

Finally, starting with mysql 4.1.2, INET_ATON() will assume 0s for missing parts, so long as you have at least two parts. That is, 1.1 will automatically be treated as 1.1.0.0, 1.0 as 1.0.0.0, and 1.2.3 as 1.2.3.0 (but 1 will be treated as 0.0.0.1). With 4.1.2 then, the above could be simplified slightly.

April 28, 2005

 

MySQL Case Study - 15

The MySQL SET Datatype: "The MySQL SET datatype is not commonly used for a few reasons; First, using the MySQL SET datatype limits you to 64 elements. While you could get around this by using multiple SETs, this still represents a loss of versatility. Second, you cannot include commas in your set elements, as the comma is an element separator. Third, using a set means your data is not normalized. In our above example, we are tracking a person's interests for a hypothetical dating site. In a normalized schema, there should be three tables: one for the person, one for all possible interests, and one that links a person to their particular interests. Fourth, an INDEX on a set datatype is going to refer to the set as a whole and will not be used for searching individual elements (this may or may not be a problem for certain applications)."

The example of 3 tables is discussed here...
http://lists.mysql.com/mysql/182348

April 27, 2005

 

MySQL Case Study - 14

Selecting numbers
I have a column like this "my_col varchar(20) null".
The values in the column can be text or numbers. How can I select only
those rows where the value in this column is a valid number?
I need something like IS_DECIMAL(), but I can't find that function.
The following SQL fails to do the job

SELECT
MIXED_COLUMN,
MIXED_COLUMN + 0
FROM
TABLE
WHERE
MIXED_COLUMN =
MIXED_COLUMN + 0;

Is there a way I can run a query that selects from a column only numbers and not letters?

_____


You were on the right track. Casting a string to a number results in a 0 if MySQL can't make a proper conversion, which is slightly counter-intuitive. This might suit your needs:

mysql> select * from mixed_num;
+--------+
| my_col |
+--------+
| a |
| 0 |
| 1 |
| abc123 |
| 123abc |
| 1.2 |
| -1 |
+--------+
7 rows in set (0.12 sec)

1) Starting with a number:

mysql> select my_col, my_col + 0 from mixed_num where my_col = '0' OR my_col + 0 != 0;
+--------+------------+
| my_col | my_col + 0 |
+--------+------------+
| 0 | 0 |
| 1 | 1 |
| 123abc | 123 |
| 1.2 | 1.2 |
| -1 | -1 |
+--------+------------+
5 rows in set (0.00 sec)

Note that '123abc' is changed to '123', which may make a big difference to you.
A less magical way to get at these numbers is using REGEXP:

2) Numbers anywhere:

mysql> select my_col from mixed_num where my_col REGEXP '[[:digit:]]';
+--------+
| my_col |
+--------+
| 0 |
| 1 |
| abc123 |
| 123abc |
| 1.2 |
| -1 |
+--------+
6 rows in set (0.12 sec)

Note that rows having a digit in them are returned.


3) Unsigned decimals:

mysql> select my_col from mixed_num where my_col REGEXP '^[0-9.]+$';
+--------+
| my_col |
+--------+
| 0 |
| 1 |
| 1.2 |
+--------+
3 rows in set (0.00 sec)

4) Unsigned integers:

mysql> select my_col from mixed_num where my_col REGEXP '^[0-9]+$';
+--------+
| my_col |
+--------+
| 0 |
| 1 |
+--------+
2 rows in set (0.00 sec)

5) Signed integers:

mysql> select my_col from mixed_num where my_col REGEXP '^-?[0-9]+$';
+--------+
| my_col |
+--------+
| 0 |
| 1 |
| -1 |
+--------+
3 rows in set (2.78 sec)

...et cetera. REGEXP is explained here:

http://dev.mysql.com/doc/mysql/en/regexp.html

April 24, 2005

 

MySQL Case Study - 13

Integer Tables explained:

Here's what I need to do...

create table wibble(
seq int(3) auto_increment primary key,
x int(5), y int(5));

insert into wibble set x=5, y=10;
insert into wibble set x=1, y=3;
insert into wibble set x=17, y=22;

mysql> select * from wibble;
+-----+------+------+
| seq | x | y |
+-----+------+------+
| 1 | 5 | 10 |
| 2 | 1 | 3 |
| 3 | 17 | 22 |
+-----+------+------+
3 rows in set (0.09 sec)

So I want to run a query to explode the x/y ranges by seq.

The required output is:

+-----+------+
| seq | z |
+-----+------+
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 1 | 4 |
| 1 | 5 |
| 2 | 1 |
| 2 | 2 |
| 2 | 3 |
| 3 | 17 |
| 3 | 18 |
| 3 | 19 |
| 3 | 20 |
| 3 | 21 |
| 3 | 22 |
+-----+------+
14 rows in set (0.17 sec)

Can anyone help me to achieve this result?

April 23, 2005

 

MySQL Case Study - 12

another collumn of counts:
I have 2 tables: users & items.

users:

userid usern age
-----------------
12 Leo 8
13 Don 7
14 Ian 9

items:

itemid itemname ofwho
----------------------
1 apple 12
2 peach 13
3 melon 13
4 apple 12
5 grape 14
6 pears 12

I want to create a 'select' query, that will retreive:

all from users where age > 7 and (how many item each user has from table items).
something like:

12 Leo 8 3
13 Don 7 2
14 Ian 9 1

how can i do this?

 

MySQL Case Study - 11

Combine newest data using JOIN and GROUP BY: Here's my problem. I have two tables, say:

items

+----+-------------------+
| ID | item |
+----+-------------------+
| 1 | Oscilloscope |
| 2 | Oscilloscope |
| 3 | Spectrum Analyser |
| 4 | Multimeter |
+----+-------------------+

and status

+----+--------+---------+------------+
| ID | mat_ID | state | date |
+----+--------+---------+------------+
| 1 | 1 | working | 2005-01-04 |
| 2 | 1 | repair | 2005-02-10 |
| 3 | 2 | working | 2005-01-04 |
| 4 | 1 | working | 2005-04-01 |
| 5 | 3 | working | 2005-02-14 |
| 6 | 4 | working | 2005-01-04 |
| 7 | 3 | broken | 2005-04-21 |
+----+--------+---------+------------+

What I want to have is a table like this:

+----+-------------------+---------------+
| ID | item | current_state |
+----+-------------------+---------------+
| 1 | Oscilloscope | working |
| 2 | Oscilloscope | working |
| 3 | Spectrum Analyser | broken |
| 4 | Multimeter | working |
+----+-------------------+---------------+

that is, combining the two tables in order to get the newest state of each item. I'm using a LEFT JOIN statement ON items.ID = status.mat_ID, but then I get one row per past and present item state. If I use GROUP BY items.ID in order to have only one state per item, I don't get the newest state. I'd like to ORDER the table by date to get the newest row, but I cannot user ORDER before the GROUP cause...

Do you get my point? :-) Any hints?

April 22, 2005

 

MySQL Case Study - 10

New table from existing tables...: I'm trying to set up a fantasy football database for my league. Here's a very basic example of 2 tables I have created: (Schedule is the league schedule using 'id's', and PtsFor is the amount of points each team scored in a given week)

Code:

Schedule
id wk1 wk2 wk3
1 2 3 4
2 1 4 3
3 4 1 2
4 3 2 1

PtsFor
id wk1 wk2 wk3
1 15 20 25
2 22 32 42
3 11 31 21
4 16 36 26



And now I would like to be able to use these tables to generate all the other tables I need (since all remaining tables I need will contain data that can be derived from these tables). For instance I would like to create the following table without having to do so manually: (the PtsAgnst table is the amount of points scored by your opponent for a given week)

Code:

PtsAgnst
id wk1 wk2 wk3
1 22 31 26
2 15 36 21
3 16 20 42
4 11 32 25

April 20, 2005

 

MySQL Case Study - 9

Composite Primary Key explained:

> Hi there, I was wondering how its possible to get the MAX of a primary
> key of a table during an insert. I basically want to create a ticket
> number, but use the primary key as part of the ticket number ie
> FAULT-0000001 or FAULT-00000002 . I tried during a sub query on an
> insert but obviouslly not working :|
>
> Let me know.
>
>

It sounds like you are generating primary keys based on some letters + an
incrementing value. That is a very user-friendly method but does not lend
itself well to MySQL. What you CAN do with mysql is to split your primary
key into two columns, one text the other an auto_increment-ed numeric.
Then, when you insert the new row of data you can use LAST_INSERT_ID() to
get the numeric value assigned to the new row.

http://dev.mysql.com/doc/mysql/en/example-auto-increment.html
http://dev.mysql.com/doc/mysql/en/information-functions.html

A demonstration might be useful:

CREATE TABLE `IncidentData` (
`IncidentType` varchar(8) NOT NULL default '',
`TypeSerial` int(10) unsigned NOT NULL auto_increment,
`... other columns here ...` varchar(255) default NULL,
PRIMARY KEY (`IncidentType`,`TypeSerial`)
);

Now to give it some base data. I will create 3 "fault" incidents, 2
"warning" incidents, and 4 "request" incidents in random order:

INSERT IncidentData (IncidentType, `... other columns here ...`)
VALUES ('request','... other column data ...')
,('warning','... other column data ...')
,('warning','... other column data ...')
,('fault','... other column data ...')
,('request','... other column data ...')
,('fault','... other column data ...')
,('request','... other column data ...')
,('request','... other column data ...')
,('fault','... other column data ...');

(Notice that I _did not_ INSERT any data into the TypeSerial column. This
was intentional as I wanted to demonstrate the group-wise auto_increment
feature.)

Now let's see what the table looks like:

localhost.test>SELECT * from IncidentData;
+--------------+------------+----------------------------+
| IncidentType | TypeSerial | ... other columns here ... |
+--------------+------------+----------------------------+
| request | 1 | ... other column data ... |
| warning | 1 | ... other column data ... |
| warning | 2 | ... other column data ... |
| fault | 1 | ... other column data ... |
| request | 2 | ... other column data ... |
| fault | 2 | ... other column data ... |
| request | 3 | ... other column data ... |
| request | 4 | ... other column data ... |
| fault | 3 | ... other column data ... |
+--------------+------------+----------------------------+
9 rows in set (0.00 sec)

Now, assume you need to add a new "fault" type incident to this table and
link some rows in another table to it. To do that you need the PK (as you
already said) of the new row. Fortunately you already know HALF of the key
(what type of incident you are creating). What you need is the other half,
the auto_incremented number. That's where LAST_INSERT_ID() comes in

INSERT IncidentData (IncidentType, `... other columns here ...`
VALUES ('fault','... new record column data ...');

SELECT LAST_INSERT_ID();
+------------------+
| last_insert_id() |
+------------------+
| 4 |
+------------------+
1 row in set (0.00 sec)

Which is the last auto_increment value issued to your connection. As long
as you are entering records one at a time, it will represent the numeric
half of the PK for the last row you entered. Check it if you don't believe
me:

SELECT * from IncidentData;
+--------------+------------+--------------------------------+
| IncidentType | TypeSerial | ... other columns here ... |
+--------------+------------+--------------------------------+
| request | 1 | ... other column data ... |
| warning | 1 | ... other column data ... |
| warning | 2 | ... other column data ... |
| fault | 1 | ... other column data ... |
| request | 2 | ... other column data ... |
| fault | 2 | ... other column data ... |
| request | 3 | ... other column data ... |
| request | 4 | ... other column data ... |
| fault | 3 | ... other column data ... |
| fault | 4 | ... new record column data ... |
+--------------+------------+--------------------------------+
10 rows in set (0.00 sec)

So the PK of your new row is ('fault',4) and that's what you use as the FK
value(s) on your child table (since you have a two column PK on your
parent table, you need two FK columns on any of its child tables to hold
the value) . So far so good? However you want to present the data as
XXXXX-0000000. That is now reduced to a simple formatting issue that can
be solved either on your front end or with a query like:

SELECT CONCAT(UCASE(IncidentType),'-',LPAD(TypeSerial,8,'0')) as Serial
, IncidentType
, TypeSerial
FROM IncidentData;
+------------------+--------------+------------+
| Serial | IncidentType | TypeSerial |
+------------------+--------------+------------+
| FAULT-00000001 | fault | 1 |
| FAULT-00000002 | fault | 2 |
| FAULT-00000003 | fault | 3 |
| FAULT-00000004 | fault | 4 |
| REQUEST-00000001 | request | 1 |
| REQUEST-00000002 | request | 2 |
| REQUEST-00000003 | request | 3 |
| REQUEST-00000004 | request | 4 |
| WARNING-00000001 | warning | 1 |
| WARNING-00000002 | warning | 2 |
+------------------+--------------+------------+
10 rows in set (0.00 sec)

Does that help with your problem?

**ALSO, splitting the type of the incident and the serial number into
separate columns will help you to isolate certain types of incidents
without resorting to substring analyses. Since the IncidentType is the
left-most column in the PK, this query is blazingly fast

SELECT ...
FROM IncidentData
WHERE IncidentType = 'fault';

whereas if you had left it as a combined text field you would have had to
do something like

SELECT ...
FROM IncidentData
WHERE IncidentType LIKE 'fault-%';

Which is not nearly as quick (especially for larger tables);

April 14, 2005

 

MySQL Case Study - 8

Left Join with count
I have a database of books with 2 tables: category and book_category. They are pretty self explanitory as to what they do.

CREATE TABLE category ( category_number INTEGER, category_name VARCHAR(20) );

INSERT INTO category values ( 1, 'Fiction' );
INSERT INTO category values ( 2, 'Non-Fiction' );
INSERT INTO category values ( 3, 'Educational' );
INSERT INTO category values ( 4, 'Childrens' );
INSERT INTO category values ( 5, 'Sports' );
INSERT INTO category values ( 6, 'Biographies' );
INSERT INTO category values ( 7, 'Business' );
INSERT INTO category values ( 8, 'Computers' );
INSERT INTO category values ( 9, 'Travel' );
INSERT INTO category values ( 10, 'Mysteries' );

CREATE TABLE book_category ( book_isbn VARCHAR(10), category_number INTEGER );

INSERT INTO book_category values ( '0471293539', 6 );
INSERT INTO book_category values ( '2884127542', 3 );
INSERT INTO book_category values ( '0158233185', 5 );
INSERT INTO book_category values ( '6239671274', 1 );
INSERT INTO book_category values ( '8827319543', 1 );
INSERT INTO book_category values ( '9251234712', 1 );
INSERT INTO book_category values ( '9254123815', 1 );

Which category of book do you have the most?

April 13, 2005

 

MySQL Case Study - 7

Simple Left Join

I have the following two tables in my database:
(In both tables the ID field is unique).

Table1
ID, first, last
1 John Smith
2 Joe Blow
3 Bill Stickers

Table2
ID, event1, event2
1 2005-04-13 NULL
3 2001-01-01 NULL

The following query

SELECT Table1.ID, Table1.first, Table1.last, Table2.event1, Table2.event2
FROM `Table1`, `Table2`
WHERE Table1.ID = Table2.ID
ORDER BY Table1.ID;

returns the output:

1 John Smith 2005-04-13 NULL
3 Bill Stickers 2001-01-01 NULL

How can I alter the query so that it outputs the rows from Table1 that have no coresponding row in Table2, ie:

2 Joe Blow NULL NULL

It is my intention that for every record in Table1 there will be a matching one in Table2 but I need to find out which ones are missing.

April 12, 2005

 

Why standards?

1) Portable: Other developers should be able to read, understand and reuse your code.
2) Understand: properly formatted query is easy to understand.
Which one of the following two are easier to understand?

SELECT reviews.ID, reviews.artist_ID, reviews.reviewer_id FROM reviews LEFT JOIN artists ON reviews.artist_ID = artists.ID LEFT JOIN reviewers
ON reviewers.ID = reviews.reviewer_id LEFT JOIN labels ON labels.ID = reviews.band_id ORDER BY artists.Artist_Name;

SELECT reviews.ID, reviews.artist_ID, reviews.reviewer_id
FROM reviews LEFT JOIN artists
ON reviews.artist_ID = artists.ID
LEFT JOIN reviewers
ON reviewers.ID = reviews.reviewer_id
LEFT JOIN labels
ON labels.ID = reviews.band_id
ORDER BY artists.Artist_Name;

3) Uniformity: If you use the same rules everywhere in your programme, the code will look uniform.
4) Caching: The latest version of Mysql will cache query results and throw out the results much faster if the same query is used again. Queries are compared before caching, so the following two queries are regarded as different by the query cache:

SELECT * FROM tbl_name
Select * from tbl_name

Queries must be exactly the same to be seen as identical and to be cached.

April 11, 2005

 

MySQL Case Study - 6

I need a select that show me if some users dont have something.
In the following example, john have wood and salt but andy have only wood, so I need a select that returns the user andy with only salt item.

table user
user_id user_name
1 john
2 andy

table stuff
stuff_id stuff_name
1 wood
2 salt

table master
stuff_id user_id
1 1
2 1
1 2

April 08, 2005

 

Ask Excel experts

If there is any excel related question you will like to ask,
mrexcel.com is one of the best message board. Here is an example how
thorough answers are provided, no matter how the trivial questions you
may ask.
http://tinyurl.com/9wli

If you don't want to register at mrexcel or need a quick and short
reply, here is the google group for excel users.
http://groups-beta.google.com/group/microsoft.public.excel

April 05, 2005

 

Fixing Word Table Madness

The first thing I did was to get rid of all of those obnoxious styles. I selected the entire document with Ctrl + A and hit Ctrl + Spacebar to remove much of the applied formatting and then hit Shift + N to set the contents all to Normal style.
The next step was to separate the large table into smaller tables, thereby allowing me to work with each row issue, separately.


http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=536


 

MySQL Case Study - 5

Find - Replace
I need to replace the word Interbrew with InBev in every instance that it appears in the Inl_custom table cust5 field. I also need to make sure that only the word Interbrew is replaced rather than replacing all of the text in that row.

 

MySQL Case Study - 4

How do I select ONLY the numeric data from a column?

 

MySQL Case Study - 3

what is wrong with the following create table statement?

create table subscribers(
userID INT NOT NULL,
listID INT NOT NULL,
FOREIGN KEY (userID) REFERENCES users(userID) ON DELETE CASCADE,
FOREIGN KEY (listID) REFERENCES mailingLists(listID) ON DELETE CASCADE,
Primary Key (listID, userID)) TYPE = INNODB;

 

MySQL Case Study - 2

You have been provided with the code for parents (for e.g. A01) and their children. The children can have son or daughter. Therefore a code (for e.g. A02) may exist in both columns, parent as well as child. The amount column mentions the income earned from different partnerships.
You need to calculate the total net worth of each person in that family.

CREATE TABLE family (SN INT, parent CHAR(4), child CHAR(4), amount INT);
INSERT INTO family VALUES (1, 'A01', 'A02', '1000'), (2, 'A01', 'A03', '1000'), (3, 'A02', 'A04', '500'), (4, 'A03', null, '1000'), (5, 'A04', null, '200'), (6, 'A05', null, '1500');

April 04, 2005

 

MySQL Case Study - 1

The "parts" table have 2 columns. One for Supplier ID and the other for the product color supplied. Some suppliers (No. 105) sell only the blue color product. Some supply (No. 104) only Red color.
Question:
How do I list all the suppliers that provide both, a red AND blue color products.

CREATE TABLE `parts` (
`pnum` int(11) default NULL,
`color` varchar(33) default NULL
) TYPE=MyISAM;

INSERT INTO `parts` VALUES ( '102', 'blue');
INSERT INTO `parts` VALUES ( '103', 'red');
INSERT INTO `parts` VALUES ( '102', 'red');
INSERT INTO `parts` VALUES ( '104', 'red');
INSERT INTO `parts` VALUES ( '105', 'blue');

April 02, 2005

 

PC + RSS + Mobile

Yahoo publicly launched a feature on Yahoo! Mobile for users to get their RSS feeds from My Y! on their mobile phone (all WAP 2.0 devices). You just go to mobile.yahoo.com on your phone (or access Yahoo! from your provider's menu) and then click on "News" and then "My Headlines."

 

Word tips

1) Formatting Tip
When setting up a Word document, it is typically most efficient to define your document margins first, then your page layout, then your paragraphs, and finally your individual character formatting. The reason for moving from the "larger picture" toward the smaller when formatting is because changes in the more encompassing items affect those with a smaller scope.

2) Full screen Keyboard shortcut
The normal way of switching to full-screen mode is to choose View | Full Screen. You exit the mode by either clicking the Close Full Screen button or by pressing Esc.

To create your own shortcut, follow these steps:
1. Choose Customize from the Tools menu. Word displays the Customize dialog box.
2. Click the Keyboard button. Word displays the Customize Keyboard dialog box.
3. In the list of Categories, choose View.
4. In the list of Commands, choose ToggleFull.
5. Place the insertion point in the Press New Shortcut Key box.
6. Press the shortcut key you want to use, such as F11.
7. Click Assign.
8. Close the dialog boxes.

Archives

June 2001   July 2001   January 2003   May 2003   September 2003   October 2003   December 2003   January 2004   February 2004   March 2004   April 2004   May 2004   June 2004   July 2004   August 2004   September 2004   October 2004   November 2004   December 2004   January 2005   February 2005   March 2005   April 2005   May 2005   June 2005   July 2005   August 2005   September 2005   October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006   January 2007   February 2007   March 2007   April 2007   June 2007   July 2007   August 2007   September 2007   October 2007   November 2007   December 2007   January 2008   February 2008   March 2008   April 2008   July 2008   August 2008   September 2008   October 2008   November 2008   December 2008   January 2009   February 2009   March 2009   April 2009   May 2009   June 2009   July 2009   August 2009   September 2009   October 2009   November 2009   December 2009   January 2010   February 2010   March 2010   April 2010   May 2010   June 2010   July 2010   August 2010   September 2010   October 2010   November 2010   December 2010   January 2011   February 2011   March 2011   April 2011   May 2011   June 2011   July 2011   August 2011   September 2011   October 2011   November 2011   December 2011   January 2012   February 2012   March 2012   April 2012   May 2012   June 2012   July 2012   August 2012   October 2012   November 2012   December 2012   January 2013   February 2013   March 2013   April 2013   May 2013   June 2013   July 2013   September 2013   October 2013   January 2014   March 2014   April 2014   May 2014   July 2014   August 2014   September 2014   October 2014   November 2014   December 2014   January 2015   February 2015   March 2015   April 2015   May 2015   June 2015   July 2015   August 2015   September 2015   January 2016   February 2016   March 2016   April 2016   May 2016   June 2016   July 2016   August 2016   September 2016   October 2016   November 2016   December 2016   January 2017   February 2017   April 2017   May 2017   June 2017   July 2017  

This page is powered by Blogger. Isn't yours?