0

This is something that has intrigued me a lot recently. It's a general SQL/Relational Database problem coming from a guy who prefers Mongo.

What I want is, to, as such, associate data from different tables in the most efficient, easiest way, without using associations and assuming I can't restructure or re-model the db.

So, for example, with FQL (which doesn't have associations), if I asked for the name and eid of all the events my current user has been invited to, I'd also like to know whether my current user is going, but that info is in the 'event_member' table.

In this instance I've an interest in another column (rsvp_status) in event_member, one that I'd like to be associated with the columns from event, i.e eid and name.

In this case the instinct may be to say that since every event has a name, an eid and a rsvp_status then we could say sort by eid and then match each nth item (for n=1 to whatever), because there's guaranteed to be the same number, but there are many cases when we can't do that.

And I know I could do separate queries and then iterate through and match them by eid, but basically I'm looking for a generic, simple,efficient solution for the associations idea if one exists. Preferably in javascript.

Niall Paterson
  • 3,580
  • 3
  • 29
  • 37

1 Answers1

2

What you are looking for here is a simple JOIN of two or more tables. http://www.w3schools.com/sql/sql_join.asp You do not have to have any relations between tables in order to perform JOINS. The relations are just a constraint to ensure that bad/invalid data can't propagete to the tables. For example an event_member with eid of unexisting user. Anyway you are free to JOIN tables as you like :)

Here is a way to connect to Sql Server using javascript How to connect to SQL Server database from JavaScript in the browser?

Community
  • 1
  • 1
Mihail Shishkov
  • 14,129
  • 7
  • 48
  • 59