In MS access, I have a query that i filter with a list of keywords through a second query. The second select query (which acts as a filter) takes the original (data) query and a keyword table and selects from the data query only the entries that match one of the keywords in the list.
I want to edit a field in the resulting query but access doesnt let me. From what i gather from google & Co. My issue might be caused by not having a relationships between the data query and the keyword table. What can i do to enable editing of the data ? If i were to create a relationship between the keyword table and the data query, how would i design it since 1 keyword does not correspond to one entry in the data query.
Edit: here is the SQL code
Select Sales.saleID, Sales.saleText1, Sales.saleText2, Sales.clientFirstName, Sales.clientLastName, Sales.clientOk
From Sales, Keywords
Where (((Sales.saleText1) Like Keywords!Keyword)) or (((Sales.saleText2) Like Keywords!Keyword));
This returns the correct data but then i cannot edit the clientOk field in the datasheet view (clientOk is a number field)
Thanks in advance for the help
Try something like this:
Select
Sales.saleID, Sales.saleText1, Sales.saleText2, Sales.clientFirstName, Sales.clientLastName, Sales.clientOk
From
Sales
Where
(Sales.saleText1 In (Select [Keyword] From Keywords))
or
(Sales.saleText2 In (Select [Keyword] From Keywords));
Related
I have a question about replace function (or anything similar to that).
I have a query that returns more than 1500 results and one of the columns is a 'BODY' column which includes inside sql query.
The columns of the returned table are: Id,name, date, title, body.
In the body column i have sql query such as:
"select * from tbl.student s inner join tbl.teacher t on s.id = t.sId
where title like '%Joni%'"
And than I have a separate list of 60 tables which some of them for example: tbl.student, tbl.teacher, tbl.class, tbl.school and etc.
I want to run on all 1500 results that iv'e got, look for each result if body field contains one of the tables that in the list (tbl.student, tbl.teacher, tbl.class, tbl.school ...
) and if so i want to replace tbl. to abc.
For example, if one of the results contains in its body field tbl.student I want to replace it to abc.student
What will be the most effective way to do that?
Thanks!
I have a query i have been working on trying to get a specific set of data, join the comments in duplicate phone numbers of said data, then join separate tables based on a common field "entry_id" which also happens to be the number on the end of the word custom_ to pull up that table.
table named list and tables containing the values i want to join is custom_entry_id (with entry_id being a field in list in which i need the values of each record to replace the words in order to pull up that specific table) i need entry_id from the beginning part of my query to stick onto the end of the word custom for every value my search returns to get the fields from that custom table designated for that record. so it will have to do some sort of loop i guess? sorry like i said I am at a loss at this point
this is where i am so far:
SELECT * ,
group_concat(comments SEPARATOR '\r\n\r\n') AS comments_combined
FROM list WHERE `status` IN ("SALEA","SALE")
GROUP BY phone_number
//entry_id is included in the * as well as status
// group concat combines the comments if numbers are same
i have also experimented on test data with doing a full outer join which doesnt really exist. i feel if you can solve the other part for me i can do the joining of the data with a query similar to this.
SELECT * FROM test
LEFT JOIN custom_sally ON test.num = custom_sally.num
UNION
SELECT * FROM test
RIGHT JOIN custom_sally ON test.num = custom_sally.num
i would like all of this to appear with every field from my list table in addition to all the fields in the custom_'entry_id' tables for each specific record. I am ok with values being null for records that have different custom fields. so if record 1 has custom fields after the join of hats and trousers and record 2 has socks and shoes i realize that socks and shoes for record 1 will be null and hats and trousers for record 2 will be null.
i am doing all this in phpmyadmin under the SQL tab.
if that is a mistake please advise as well. i am using it because ive only been working with SQl for a few months. from what i read its the rookie tool.
i might be going about this all wrong if so please advise
an example
i query list with my query i get 20,000 rows with columns like status, phone_number, comments, entry_id, name, address, so on.
now i want to join this query with custom fields in another table.
the problem is the custom tables' names are all linked to the entry_id.
so if entry_id is 777 then the custom table fields are custom_777
my database has over 100 custom tables with specials fields for each record depending on its entry_id.
when i query the records I don't know how to join the custom fields that are entry_id specific to the rest of my data.i will pull up some tables and data for a better example
this is the list table:
this is the custom_"entry_id"
Full Outer Join in MySQL
for info on full outer joins.
I've been reading through tutorials on Rails' active record model operations. And I'm a little confused on the difference between .select and .group. If I wanted to get all the names of all my users in table User I believe I could do:
myUsers = User.select(:name)
so how would that be different from saying:
myUsers = User.group(:name)
thanks,
Will
The two differ like this:
User.select(:name)
is equivalent to this SQL statement
SELECT name from users;
and
User.group(:name)
is equivalent to
SELECT * from users GROUP BY name;
The difference is that with select(:name) you are taking all rows ordered by id, but only with column name. With group(:name) you are taking all rows and all columns, but ordered by column name.
User.pluck(:name) will be the fastest way to pull all the names from your db.
There is #to_sql method to check what DB query it is building. By looking at the DB query, you can confirm yourself what is going on. Look the below example :-
arup#linux-wzza:~/Rails/tv_sms_voting> rails c
Loading development environment (Rails 4.1.4)
>> Vote.group(:choice).to_sql
=> "SELECT \"votes\".* FROM \"votes\" GROUP BY choice"
>> Vote.select(:choice).to_sql
=> "SELECT \"votes\".\"choice\" FROM \"votes\""
>>
Now it is clear that Vote.select(:choice) is actually, SELECT "votes"."choice" FROM "votes", which means, select choice column from all rows of the table votes.
Vote.group(:choice) is grouping the rows of the votes table, based on the column choice and selecting all columns.
If I wanted to get all the names of all my users in table User.
Better is User.pluck(:name).
MySQL: 5.6
I have 2 tables - one has a VARCHAR column containing email addresses, and the other has a VARCHAR column with domain names.
Sample email address: john#yahoo.co.uk
Sample domain name: yahoo.co.uk
I need to retrieve the list of email addresses that belong to domains that are in the domains table.
How can I accomplish this most efficiently?
Thanks in advance for any responses.
You can use LIKE on this. (use for string matching)
But the problem with using LIKE is that it doesn't use any index that is provided on the column. This will likely to perform better on database with smaller records but on big database that already contains thousands of records it will have poor in performance. The reason for that is because it will do FULL TABLE SCAN that runs on every record on the table which is very slow.
SELECT a.DomainName, b.EmailAdd
FROM DomainList a
INNER JOIN EmailList b
ON b.EmailAdd LIKE CONCAT('%', a.DomainName)
SQLFiddle Demo
To further gain more knowledge about joins, kindly visit the link below:
Visual Representation of SQL Joins
You should be able to JOIN on both tables and uses LIKE with CONCAT:
SELECT D.Domain, E.Email
FROM Domains D
JOIN Emails E ON E.Email LIKE CONCAT('%',D.Domain)
SQL Fiddle Demo
I first need to query a table of people to find all the families I want. This query does the job nicely: (from m in Members where m.Lastname.StartsWith("A") select m.FamilyID).Distinct()
The above returns me a short list of FamilyIDs (integer). I need Distinct because a family can have more than one member.
How do I then join this list to another table to retrieve all rows in that second table where a column called FamilyID whose values are in the first list?
Is there something like IN in Transact-SQL?
Thanks.
Yes, Linq to sql has the Contains that does something similar. It is just really the other way around in syntax so you need to get used to it but it works like a charm.
Have a look here http://wekeroad.com/2008/02/27/creating-in-queries-with-linq-to-sql/