Parse & JS: Basic Query

This entry is part 14 of 25 in the series Parse & Javascript

Say we have these data in the table and we have like to find out the movie that was released in the year 2013.

The general pattern is to create a Parse.Query, put conditions on it, and then retrieve an Array of matching Parse.Objects using find.

For example, to retrieve of the title of the movie with a particular releaseYear, use the equalTo method to constrain the value for a key.

movObject

<!doctype html>
<head>
    <title>My Parse App</title>
    <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
    <script type='text/javascript' src='http://www.parsecdn.com/js/parse-1.2.17.min.js'></script>
</head>

<body>

<div>
    <div style='display:none' class='error'>
        <h1>Movie not found</h1>
    </div>

    <div style='display:none' class='success'>
        <h1>Movie Found</h1>
    </div>
</div>

<script>
    Parse.initialize('5d3sro43zBGj8AMYqWND5bFYMzAan7f5P5euZm7M', 'hlRZZqAylA7Fmah4Kk6ma8WK7QCT4cHrxjafnnkI');
    var MovieObj = Parse.Object.extend('MovieObj');
    var movieObj = new MovieObj();

    var query = new Parse.Query(MovieObj);

    query.equalTo('releaseYear', 2013);

    query.find(
            {
                success: function(movieObj) {
                    $('.success').show();
                    var title = movieObj[0].get('titleName');
                    alert(title);
                }
            }
    );

</script>

</body>
</html>
Try The Code

The array name of the matching Parse.Object is movieObj and we use movieObj[0].get to retrieve the title of the movie.

MySQL Clients: Query DB

This entry is part 4 of 8 in the series MySQL Clients

Let’s make a simple query through Toad.

select * from artist

From the menu, go to Tool -> Editor.

Type in the above query and execute the sql.

toadquery

Let’s end this tutorial by dropping the table and the database.  In our next tutorial, we will create again the database and table using PHP.

Execute the below 2 sql scripts to remove the table and the database.

drop table artist
drop database allartist

You can verify if you have removed the database successfully by login in using PHPMyAdmin.

SQL: More Select Examples

This entry is part 9 of 20 in the series SQL Tutorial

Using the same table, let’s try more select statements.

If you work in the IT industry, and there are databases in your applications, being proficient with querying the database could become crucial to your daily work.

create table artiste
	(
 id int auto_increment primary key, 
 artiste varchar(30), 
 album varchar(50),
 year int(10)
 );

insert into artiste
(artiste, album, year)
values
('Rod Stewart', 'Maggie May', 1973),
('New Order', 'Substance', 1987),
('Nirvana', 'Smell Like Teen Spirit', 1992),
('Rod Stewart', 'Out of Order', 1988);
IDartistealbumyear
1Rod StewartMaggie May1973
2New OrderSubstance1987
3NirvanaSmell Like Teen Spirit1992
4Rod StewartOut of Order1988