MYSQL : Query data

SELECT
        column_name1,
        column_name2...
FROM
        tables
[WHERE conditions]
[GROUP BY group
        [HAVING group_conditions]
]
[ORDER BY sort_columns]
[LIMIT limits];

Example:
SELECT
        tbl_users.id,
        tbl_users.username,
        tbl_users.`password`,
        tbl_users.firstname,
        tbl_users.lastname
FROM
        tbl_users;

WHERE Clause - select a particular rows which match its conditions
SELECT
        tbl_users.id,
        tbl_users.username,
        tbl_users.`password`,
        tbl_users.firstname,
        tbl_users.lastname
FROM
        tbl_users
WHERE
        tbl_users.id = '1';

GROUP BY- allows use to retrieve rows in group
SELECT
        tbl_users.id,
        tbl_users.username,
        tbl_users.`password`,
        tbl_users.firstname,
        tbl_users.lastname
FROM
        tbl_users
GROUP BY
        tbl_users.lastname

ORDER BY - sort the result set on one or more column in ascending or descending order
SELECT
        tbl_users.id,
        tbl_users.username,
        tbl_users.`password`,
        tbl_users.firstname,
        tbl_users.lastname
FROM
        tbl_users
ORDER BY
        tbl_users.lastname

1 comments:

How To Win At Slot on June 5, 2011 at 3:25 AM said...

Interesting variant