Sie sind auf Seite 1von 3

SELECT * FROM users where campaignid=101;

SELECT userid, entryid, count(*) FROM ratingaction where userid=5649 and entryid
=106976;
SELECT userid, entryid, count(*) FROM ratingaction where userid in (SELECT id FR
OM users where campaignid=101) and entryid in (SELECT id FROM entries where camp
aignid=101) group by userid;
********************************************************************************
********************************************
group by changes the way results are displayed. Consider the following query:
SELECT userid, entryid, count(*) FROM ratingaction where userid in (SELECT id FR
OM users where campaignid=101) and entryid in (SELECT id FROM entries where
campaignid=101) group by userid, entryid;
userid
5648
5648
5648
5649
5649
5649
5649
5649

entryid
106894
106911
106975
106894
106911
106975
106976
106978

count(*)
1
1
1
1
3
1
1
1

Without
userid
5648
5649

entryid
entryid
106894
106894

in group by:
count(*)
3
7

without group by:


userid entryid count(*)
5648
106894 10
********************************************************************************
********************************************
--> Document SQLite Distinct, not in, group by
select * from check_list_items where parent_id = 1 and name not in (select name
from check_list_items where parent_id != 1)
select distinct name from check_list_items where parent_id != 1 and name not in
(select name from check_list_items where parent_id = 1) ORDER BY name ASC
select id, name from check_list_items group by lower(name)
select name, parent_id from check_list_items where parent_id != 1 and name not i
n (select name from check_list_items where parent_id = 1) GROUP BY lower(name)
query = [NSString stringWithFormat:@"select id, name, is_ticked from check_list_
items where parent_id != %d and name not in (select name from check_list_items w
here parent_id = %d) GROUP BY lower(name)", addedCheckListId, addedCheckListId];
********************************************************************************
********************************************
How to insert a text in a table with quotes in it?
NSString* str = @"There's an quote here";
//
// Escape quote before updating table.
//

str = [str stringByReplacingOccurrencesOfString:@"'" withString:@"''"];


NSString* query = [NSString stringWithFormat:@"UPDATE products SET desc = '%@' W
HERE id = 1", str];
********************************************************************************
********************************************
How to select rows in table1 based on some crieteria satisfied in table2?
SELECT id, english, spanish FROM basics WHERE ((lower(english_search) LIKE '%dri
ver%' or lower(spanish_english) LIKE '%driver%')) or id in (SELECT basics_id fro
m answers WHERE ((lower(english_search) LIKE '%driver%' or lower(spanish_english
) LIKE '%driver%')))
Explanation:
a) Select id, english, spanish of the rows from basics that have the text 'drive
r' in it.
b) Select id, english, spanish of the rows from basics whose id match with ids r
eturned by answers table.

********************************************************************************
********************************************
SELECTfoods.item_name,foods.item_unit,company.company_name,company.company_cityFROM
companyWHEREfoods.company_id= company.company_id;
http://www.w3resource.com/sql/joins/using-a-where-cluase-to-join-two-tables-rela
ted-by-a-single-column-primary-key-or-foriegn-key-pair.php#sthash.ao4YFjM4.dpuf
********************************************************************************
********************************************
How to have column in query result with values not from database?
select id, 0 from basics.
********************************************************************************
********************************************
How to find whether a column in database is empty?
NSString* query = @"select id, title, price from products";
//
// Assume that title and price are empty.
//
SQLiteResult* result = [SQLite query:query];
if ([result.errorCode isEqualToString:@"OK"])
{
int recordCount = [result.rows count];
NSArray* row = nil;
for (int index = 0; (index < recordCount); index++)
{
row = [result.rows objectAtIndex:index];
for (NSUInteger count = 0; (count < 3); count++)
{
if ([[row objectAtIndex:count] length] == 0)
{
NSLog(@"row with id %d has column %d as empty",
index, count);

}
}
}
}
********************************************************************************
********************************************
How to select 10 after 20th row?
select * from table limit 10 offset 20
********************************************************************************
********************************************
--> How to create a new table from existing table with columns reordered?
table1 columns: A, B, C, D. Create table by reversing the column order.
create table table2 as select D, C, B, A from table1
********************************************************************************
********************************************
SELECT id, english_content, french_content FROM basics_detail_list WHERE ((lower
(english_content_search) LIKE '%man%' or lower(french_content_search) LIKE '%man
%'))

Das könnte Ihnen auch gefallen