Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created tables for a fictional lab society. One of the tables is called "labbranch" and I am trying to create an SQLite query that selects the ones that are equal to or over 100m.

The "labbranch" table has 6 rows: labid, name, address, phone, sizeoflab, totaldeskspace. I have only included three entries, two of which are over 100m.

thank you

What I have tried:

SELECT sizeoflab
FROM lab
WHERE sizeoflab=100;

When I tried this statement, I received an error
Posted
Updated 2-Apr-16 6:51am
Comments
CHill60 2-Apr-16 11:58am    
What was the error?
And if you want the ones that are equal to or over 100m then shouldn't you be using WHERE sizeoflab>=100;<code>?
And if the data is in a table called "labbranch" should that line be
FROM labbranch
illsmith 2-Apr-16 12:52pm    
Oh sorry, that's what I meant.

The error says:
no such column: sizeoflab: SELECT sizeoflab
FROM labbranch
WHERE sizeoflab>=100;

I tried WHERE sizeoflab>=100; but I am still getting the same

CHill60 2-Apr-16 13:00pm    
Make sure you have spelled the column name correctly

1 solution

Ok. I created your table and populated it thus:
SQL
create table labbranch
(
 labid int, 
 name varchar(50), 
 address varchar(50), 
 phone varchar(50), 
 sizeoflab int, 
 totaldeskspace int
);

insert into labbranch values(1,'Lab1','@Lab1','111', 99, 99);
insert into labbranch values(2,'Lab2','@Lab2','222', 100, 100);
insert into labbranch values(3,'Lab3','@Lab3','333', 101, 101);

Note that the table has 6 columns (not rows) and 3 rows (entries)
Your requirements are
Quote:
selects the ones that are equal to or over 100m
So my expected results based on your description are to get details for Lab2 and Lab3.

When I run the query you have already tried I get an error message:
Quote:
TypeError: Unable to get property 'substring' of undefined or null reference
This is because you do not have a table called lab. Fix that by using the correct table name:
SQL
SELECT sizeoflab
 FROM labbranch
 WHERE sizeoflab=100;

When I run that I get a single number, 100, returned. From my expected results I wanted 2 rows not one, and there isn't any useful information in the results I currently have either.

So change it to
SQL
SELECT labid, name, sizeoflab FROM labbranch
 WHERE sizeoflab >= 100;

Which gives the results:
labid name sizeoflab
2     Lab2 100
3     Lab3 101
 
Share this answer
 
Comments
illsmith 2-Apr-16 13:09pm    
That seems to have done it. Thanks very much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900