I have a script that should select from table all rows, order by id but only one row per select. This selection is made when a button is pressed. But I think that query is wrong, it selects only first row. Why?
private void select(){using (Conexiune.getConnection()){string select = "SELECT DISTINCT * FROM questions ORDER BY id ASC LIMIT 1";SQLiteCommand cmd = new SQLiteCommand(select, Conexiune.getConnection());cmd.CommandType = CommandType.Text;SQLiteDataReader rdra = cmd.ExecuteReader(CommandBehavior.CloseConnection);try{while (rdra.Read()){textBox1.Text = rdra["question"].ToString();textBox2.Text = rdra["answer1"].ToString();textBox3.Text = rdra["answer2"].ToString();textBox4.Text = rdra["answer3"].ToString();r1 = (int)rdra["option1"];r2 = (int)rdra["option2"];r3 = (int)rdra["option3"];SimulatorManager.Intrebare = textBox1.Text;}}catch (InvalidOperationException ex){MessageBox.Show(ex.Message);}}}

Pankaj Kumar ChoudharyRank #80 · 24.4K reputationPosted Mar 30, 2015, 4:36 PM EDT
Top command.
using top command you can rewrite your query as
select top(1) * from (select distinct * from questions )Ques order by Id asc
Diacu Paul5 reputationPosted Mar 30, 2015, 9:31 PM EDT
Pankaj Kumar ChoudharyRank #80 · 24.4K reputationPosted Mar 31, 2015, 4:18 AM EDT
select top(1) * from (select distinct * from questions )Ques order by Id asc
here Ques is nothing it is a name of the data that is retrieved from internal query
select distinct * from questions"
you can give any name as you want here i gave "Ques"....
Diacu Paul5 reputationPosted Mar 31, 2015, 7:45 AM EDT