When using SP 2007 and needed to do a join i just write the tables to a sql table and then use sql to join the tables.
What i really need to do is quite simple.
I have a master list and another list that users insert records too lets say a child list.
When a user opens up the master list and clicks on an item i insert a record including their usernames to the child list
All i want to show the users(based on login names) is the items they haven't read and what items.
In sql i could have done something like e.g
Select * from master where not in(select from child where username ='blalal')
Any ideas.Not sure if to do it on the client or in the object model.
Sure CAMl doesn't have joins
Thanks in advance
You can do joins in CAML queries as long as the two lists are related by a lookup field.
http://msdn.microsoft.com/en-us/library/ie/ee539975.aspx
Or you can use the Camelot .NET Connector from Bendsoft to JOIN any fields. It supports typical CRUD commands, including LEFT and INNER joins and UNION.
Check this approach very easy to join as many list as you want: Link
cawl_QueryBuilder cawl = new cawl_QueryBuilder();
cawl.Select("Users_Title");
cawl.Select("Users_Age");
cawl.Select("Users_Sex");
cawl.Select("CarBrand");
cawl.Join("UsersList";"OwnerColumn");
cawl.Get('UserCarsList');
StringBuilder Result = new StringBuilder();
foreach (SPListItem item in cawl.ListItemCollection())
{
Result.Append(item["Users_Title"].ToString() +
item["Users_Age"].ToString() +
item["Users_Sex"].ToString() +
item["CarBrand"].ToString());
}
Label1.Text = Result .ToString();
Related
My task: "Compile an SQL query that outputs a specific store (enter parameter window) the age of the youngest buyer"
I´ve tried some things, but because i´m new to SQL and i have no idea what i´m doing non of them seem to work.
I´d really appreciate, if someone would help me.
Thanks!
First you need to know the fields to SELECT (or return) and the table FROM which you are querying (asking) data; let's say you have the following tables: tblStores (containing a list of stores and related info), tblCustomers (containing customers and related info, e.g. ages, names, phone numbers, etc.), and tblPurchases (containing all the purchases at all stores by all customers and related info). You want the minimum age of a customer making a purchase at a specfic store, so you could use a MIN aggregating function. You would want to join (or relate) the tables based on customers and purchases. See my INNER JOINs in the example below. Then you filter the result by the user-inputted store name (inputStoreName) using WHERE; since the inputStoreName is undefined, in Access this would cause the parameter entry popup window to appear.
SELECT list of fields or aggregating functions you want (comma-separated)
FROM list of tables the fields are in (comma-separated) and how to join the tables
WHERE list of conditions to filter the data (separated by AND or OR)
Example:
SELECT tblStores.Name, tblStores.Description, MIN(tblCustomers.age)
FROM tblStores INNER JOIN ( tblPurchases INNER JOIN tblCustomers on tblPurchases.customerID = tblCustomer.customerID) ON tblStores.storeID = tblPurchases.storeID
WHERE (tblStores.Name = inputStoreName);
I recommend checking W3 schools. They are usually helpful for most programming tasks. If you provide more info about your database, we can provide more directed help.
I have created a database for users to "follow" TV Shows, I need to create a form to display each show and all the relevant information to that specific show.
The four tables I have are as follows:
Shows (Main Table),
Networks,
ShowGenres (Links multiple genre's to one show),
Genres.
The relationships and all fields are shown in the image below.
Currently I have a page which displays the following information:
showID, showName, showAired, networkName, showStatus, showRuntime, showSeasons, showEpisodes, showOverview.
Ideally i'd like to have a List box to display an array of the genre's associated with the specific show. I have tried for quite a while to come up with a query to do this, the closest I managed to get showed the relevant information but added duplicate pages.
Here's my latest attempt:
SELECT * FROM Shows A
INNER JOIN Networks B ON B.networkID = A.networkID
INNER JOIN ShowGenres C ON C.showID = A.showID
INNER JOIN Genres D ON D.genreID = C.genreID;
Any help would be appreciated, thanks in advance.
One has to appreciate the presentation level logic that can be used in conjunction with the data logic. Very generically - in the 1:Many - - your query of fields that include both fields will repeat the 1 table values with each of the Many records. That can not be altered via any query design as it is inherent in the data logic.
But at the presentation level you can control the display. Using a report - the data source can be the query - but report properties offer grouping whereby you can put the 1 field value as the group header - thus displaying just once; and then below it list all the many records.
It is not a list box per se though depending on how creative one gets with reports/sub reports one could potentially make that style. But in the end you must work this at the presentation level.
One method is to use exists:
select g.*
from genres as g
where exists (select 1
from showgenres as sg inner join
shows as s
on sg.showID = s.showID
where sg.genreID = g.genreID and
s.showName = ?
);
I have two tables. Table "List" and table "Content". I want to store 6 types of lists. These lists are black,white and grey lists and each of these list contain a few words. Whenever someone notices a new word that should be in one of the lists, then new word should be simply added to the database.
The image below shows you the tables that I use.
I want to refer or join a certain list for instance a list with name: "Blacklist" that has an ListID= 1 with the correct set of blacklistwords, that could have a ContentID=1.
The content is a list of words, but I am clueless as for how I should join the correct list of words(content) to a listID. I don't know how to query this.
The part that is troubeling me is that it is a list of words. So a ContentID =1 has for example the words"Login","Password", "Credential" etc. How do I query it to ListID=1 with the name"BlackList"? And do the same for the other lists?
I think it should look like this.
SELECT ID
FROM List
LEFT JOIN Content
ON LIST.ID = ContenID AND CONTENT.ISDEFAULT = 1
WHERE ListID = 1
This only joins the two ID with each other. How do I join the correct list of words with the correct list? Maybe I am totally missing the point with the query above?
Question: How do I join a set or list of words to a list with a name and ListID?
Once you change this schema, the below query will work
SELECT ListID,ContentID,Words
FROM List
LEFT JOIN Content
ON List.ListID = Content.ListID
WHERE List.ListID = 1
I have considered the schema from the diagrams. Please execute the below query:
SELECT
L.Name AS 'ListName',
C.Words
FROM List L
INNER JOIN Content C ON C.ListID = L.ListID
WHERE
C.Words IN ('Login','Password','Credential')
Background: working with MS Access as a front end and SQL Server as a back end to organize data of every student found in a school.
Well I've been working on MS Access forms and I've set the record source as a query and set the intended text boxes , combo boxes , etc... to the property that was received.
Now the problem is that the queries for every student is being executed while on the form load or changes from one record to the other. I've come to this conclusion by viewing the SQL profiler and noticed that there is a large amount of queries being executed (It take approx. 14 seconds to load one record).
Is there a way to go around this?
Here is the SQL script that is being used to retrieve the the data (Set as a record source on the form itself).
SELECT
PERSON.id, PERSON.id_number,
Student.Student_Status, PERSON.name,
PERSON.surname, PERSON.dob, PERSON.address_1, PERSON.address_2,
PERSON.town, PERSON.mobile, PERSON.telephone, PERSON.postcode,
PERSON.id, PERSON.nationality, PERSON.dual_nationality,
PERSON.gender, Student.student_type, Student.mcast_email,
PERSON.euCitizen, PERSON.email, PERSON.NI_no,
PERSON.next_of_kin, Student.Form, course.course_name,
course.course_code, CourseYear.Year, Institute.Institute_name
FROM
((((PERSON
LEFT JOIN
Student ON PERSON.ID = Student.person)
LEFT JOIN
CourseYear ON Student.id = CourseYear.student)
LEFT JOIN
Yearlyprogramme ON CourseYear.course = Yearlyprogramme.id)
LEFT JOIN
course ON Yearlyprogramme.course = course.id)
LEFT JOIN
Institute ON course.Institute = Institute.id;
These properties that are retrieved are set to the text boxes and and combo boxes to show data. Is there a way to call this query once for each student without having to the a WHERE clause on the ID?
In my experience, Access queries with multiple LEFT JOINs on linked SQL Server tables often behave very badly.
If you can't avoid the LEFT JOINs, create a SQL Server view from your query, link it in Access, and use the linked view as record source of your form.
I currently have a schema set up in the following manner:
The table tblCategoryRiskArea is set up as an intermediate table for the many-to-many relationship that can exist between Categories and RiskAreas.
Within the tblBase table, I would like to make it so that the RiskArea choices are dependant upon the Category choice. MS Access allows you to set a Lookup for a field in a table based upon a Row Source SQL statement. I am having trouble figuring out the correct SQL statement to define the Row Source for RiskArea dependant upon Category. This:
SELECT tblRiskAreas.RiskAreaID, tblRiskAreas.RiskArea
FROM tblRiskAreas INNER JOIN
((tblCategories INNER JOIN tblBase
ON tblCategories.CategoryId = tblBase.Category)
INNER JOIN tblCategoryRiskArea
ON tblCategories.CategoryId = tblCategoryRiskArea.Category)
ON (tblRiskAreas.RiskAreaID = tblCategoryRiskArea.RiskArea)
AND (tblRiskAreas.RiskAreaID = tblBase.RiskArea)
WHERE (((tblCategoryRiskArea.Category)=[tblBase]![Category]))
ORDER BY tblRiskAreas.RiskAreaID;
is the best I've come up with so far, using MS Access' Query Builder, so all of the Inner Joins have been created just by my having defined the relationships between the tables and dragging them into the Query Builder. This query returns nothing, however.
I suspect that it may have something to do with the circular nature of the relationships I set up?
Thank you.
Edited: tblRiskArea contains 4 RiskAreas, as follows:
Environmental
Health
Safety
Security
Each Category can fall into one or two of these RiskAreas, so the tblCategoryRiskArea creates the relationship bewtween them.
First remove Category and RiskArea from tblBase and replace them for CategoriRiskAreaID
You will show in your form 2 combos. First combo Catagory data source:
Select CategoryId,Category from tblCategories
Second combo Risk Areas data source:
Select a.CategoryRiskId, b.RiskArea
from tblCategoryRiskArea a
inner join tblRiskArea b
where a.RiskAreaId=b.RiskAreaId
AND a.category = #ComboBoxCategorySelectedItem
Now you have the value to insert in tblBase, ComboBoxSelectedItem is tblCategoryRiskArea.CategoryRiskId