I want to find two columns in a table that have same values through Solr, no specific value targeted. Just like mysql shown below could be done:
select A from table t
where A.value == B.value
A and B are both columns in table t.
I wanna use Solr instead of access mysql, please tell me what to do or at least give me a clue.
You can group it easy with:
group.field=id&group=true&group.limit=100
But you have still other values in this solution... It's not the best :D
Related
Working in ColdFusion, I have a MySql query which could apply to any number of tables. The particular table is stored in a variable called "basetab". So the query begins as
select * from #basetab#
I go on to check a particular column:
select * from #basetab#
<cfif basetab Eq 'RepSave'>
where RepSavArch != 'Y'
</cfif>
However, I really need to check a column in any table that is named SomethingArch. Because I know the basetab, I know what the something is. So I want to write
select * from #basetab#
where #prefix#Arch != 'Y'
This works. However, not all the tables have a 'somethingArch' column, so I need not to do this unless 'somethingArch' is there.
Can someone suggest a way to get this done. I suspect I need a subquery, but don't know how to construct it.
You can query the INFORMATION_SCHEMA's COLUMNS table. The Information Schema provides meta data about the DBMS such as what tables, columns, indexes, ... exist.
That said, I do not really understand what you are trying to achieve.
I have two tables ini mysql database
First
1.2.3.4
5.6.7.8
9.10.11.12
13.14.15.16
17.18.19.20
21.22.23.24
Second
a.b.c.d
e.f.g.h
1.2.3.4
13.14.15.16
21.22.23.24
25.26.27.28
29.30.31.32
33.34.35.36
I want to select values from the two tables and print Only values that not exist in the first table ignoring value that not exist in the second table.
The result should be :
5.6.7.8
9.10.11.12
17.18.19.20
I think I've search all the result in stackoverflow. And I know some basic mysql . But nothing gave me the result I expected. Hard to explain I know. Or maybe I made simple think complicated I don't know :D.
Thank you.
use sql distint statement.....
eg : SELECT DISTINCT City FROM Customers
I've found the answer, as it's been answered many times ,as I suspected I've made a simple thing complicated with to much data. :D.
In MySQL workbench (Mac OS), I wanted to join two tables so that I can update the second one. The code I put in was as follows
select f.company, f.remarks, c.pic
from feedback f, customers c
where f.col = c.col
order by f.company;
The output is a read only table, which prevented me from updating table "customers" based on the f.remarks column.
Your advice/suggestion is appreciated. Thank you.
By hovering above the "Read Only" icon, I got the following message:
"Statement must be a SELECT from a single table with a primary key for its results to be editable".
After some research based on the advice given by fellow coders, here are some points to note:
In MySQL workbench, one cannot edit the results obtained from any JOINs because it's not from a single table;
In using SELECT from a single table, the primary key must be included in order for the result to be editable.
Thank you to everyone who contributed to the question. I appreciate it.
The problem is because, as you mentioned, SELECT only returns a "read only" result set.
So basically you cant use MySQL workbench to update a field in a read only result set that is returned when using a JOIN statement.
from what i understand you want to update table "customers" based on a query.
maybe this post will help you:
update table based on subquery of table
I noticed te other day I can joins in mysql just as easily by doing,
SELECT peeps, persons, friends FROM tablea JOIN tableb USING (id) WHERE id = ?
In stead of using,
SELECT a.peeps, a.persons, b.friends FROM tablea a JOIN tableb b USING (id) WHERE id = ?
It only works if there is no matching column names, why should I do the second rather than the first?
No, you don't need to, but in my humble opinion you really should. It's almost always better in my experience to be explicit with what you're trying to do.
Consider the feelings of the poor guy (or girl) who has to come behind you and try to figure out what you were trying to accomplish and in which tables each column resides. Explicitly stating the source of the column allows one to look at the query and glean that information without deep knowledge of the schema.
Query 1 will work (as long as there are no ambiguous column names).
Query 2 will
be clearer
be more maintainable (think of someone who doesn't know the database schema by heart)
survive the addition of an ambiguous column name to one of the tables
So, don't be lazy because of that pitiful few saved keystrokes.
It's not necessary if you have no duplicate column names. If you do, the query will fail.
I am trying to use the results of another query to use as a criteria for another. In my specific example, I might have four houses that are 'A', 'B', 'C', 'D' (the unique values of a field in a table called Homes).
I want to go through another query and say for each house type, what percent of residents (in Residents table) are married, which I want to do by using Count() to count the number for each Home type.
Do I need to loop through the results using VBA? Asking on a higher level, is there a way to use the results from a query as inputs into another - more than just limit the results of the new query to the results of the prior query?
Edit:
In semi-pseudo code:
For each (result of previous query) Do
New query WHERE field1 = (row of previous query)
End Do
What I am trying to ask, is there a way to accomplish this in Access using SQL? Or is this something that has to be done in VBA?
I know that if it can be done in SQL that would be the best performing and best practice, but I'm relatively inexperienced in SQL and online resources aren't always helpful because Access has it's own particular flavor of SQL.
Since you are using VBA to run this, you can loop through your recordsets and yes you can use a value from one query in the next query. There are alot of resources out there to help.
VBA: Working with RecordSets
Looping through Record Sets
Code through all records
To answer your general question, yes there is. You can do a nested query i.e. select column a from table a where column a = (select column b from table b where column b=x)
You can go as many levels deep as you want, but the caveat is the nested query can only return one column and with a specific answer set. You can also use select statements as your columns i.e
select (select column b from table b) col b from table a ..... Not the exact syntax but I would have to dig out some examples from an old project to find that.
Nested queries are useful, but for the level of precision you are looking for, a stored procedure or a view is probably a better option. Just for ease of use, I would look at creating a view of the data that you want and then querying from that to start with. More flexible than a nested query.
You need to join two tables using a common column and then get your specific column from any of the table
SELECT A.REQUIRED_FIELD from TABLEA AS A
INNER JOIN TABLEB AS B ON A.FOREIGN_KEY=B.FOREIGN_KEY
WHERE CONDITION