MYSQL SELECT OF TWO TABLES AND CUTTING QUERIES
source link: https://www.codesd.com/item/mysql-select-of-two-tables-and-cutting-queries.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
MYSQL SELECT OF TWO TABLES AND CUTTING QUERIES
I have two tables wp_term_relationships
and wp_term_taxonomy
When I do the following SELECT * FROM wp_term_taxonomy WHERE parent = '17'
I get the image below
Then I do SELECT * FROM wp_term_relationships WHERE term_taxonomy_id = '28'
Which outputs
The object_id
then gets used SELECT * FROM wp_term_relationships WHERE object_id = '88'
and this shows me the terms
for this item.
What I would then like to do is show next to term_taxonomy_id
the taxonomy
name from the following table
I apologise this is a long winded question but I hope there are people who would be able to help and possibly simplify it so that from my initial query of where the parent=17
I am able to only show DISTINCT taxonomy
of where the taxonomy
is equal to product_brand
You can replace your last query by:
SELECT wptr.*, wptt.taxonomy
FROM wp_term_relationships wptr
INNER JOIN wp_term_taxonomy wptt ON wptr.term_taxonomy_id = wptt.term_taxonomy_id
WHERE object_id = '88'
It uses an INNER JOIN that will take the taxonomy name from wp_term_taxonomy for the term_taxonomy_id ID.
As Anticom said, you should have a look at the JOIN in SQL, they would solve your problem and are easy to use.
Related Articles
mySQL Select from two tables and match result
SQL queries to select from two tables and compare with third
Mysql selects from two tables
Query MySQL SELECT from a table and join the results with other tables
Select from two tables and order by datetime stamps
MySQL Selection from two tables sorted by date
The Mysql operation between two tables and the output of wishes in one
MySQL SELECT from two tables with COUNT
MYSQL selecting from two tables but the second table does not always have a relationship with the first one
Mysql select with multiple tables and flexible output
MySQL Select FROM 3 tables AND put this into a PHP array
select from two tables and conditionally change a column
MYSQl, select from two tables, count, with exception
SELECTED from two tables based on the same identifier and grouped
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK