Column 'active_users' in order clause is ambiguous
Hey RaGEZONE!
Today I first came across a mysql error in my swift emulator which pretty much said that I had to add a column active_users to my rooms table. I did that and then this came up a few times:
Code:
Error in query:
SELECT rooms.*, room_active.active_users FROM rooms LEFT JOIN room_active ON (room_active.roomid = rooms.id) WHERE owner = @query AND roomtype = 'private' UNION ALL SELECT rooms.*, room_active.active_users FROM rooms LEFT JOIN room_active ON (room_active.roomid = rooms.id) WHERE caption = @query AND roomtype = 'private' ORDER BY active_users DESC LIMIT 50
MySql.Data.MySqlClient.MySqlException (0x80004005): Column 'active_users' in order clause is ambiguous
at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int32& insertedId)
at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int32& insertedId)
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at Database_Manager.Database.Session_Details.QueryAdapter.getTable()
I have no idea what is ambiguous means or how I should fix that error, I hope that somebody is able to help me! :D
Re: Column 'active_users' in order clause is ambiguous
SELECT rooms.*, room_active.active_users FROM rooms
LEFT JOIN room_active ON (room_active.roomid = rooms.id)
WHERE rooms.owner = @query AND rooms.roomtype = 'private'
UNION ALL
SELECT rooms.*, room_active.active_users FROM rooms
LEFT JOIN room_active ON (room_active.roomid = rooms.id)
WHERE rooms.caption = @query
AND rooms.roomtype = 'private'
ORDER BY active_users DESC
LIMIT 50
Dont know the exact structure of the tables, but this should do it.
Re: Column 'active_users' in order clause is ambiguous
ORDER BY active_users DESC LIMIT 50
to
ORDER BY room_active.active_users DESC LIMIT 50 ?
Re: Column 'active_users' in order clause is ambiguous
I'll try both, thanks! :)